Skip to main content

How to Work With Frames in Selenium Web Drivers

An iFrame is a another HTML document embedded inside the HTML document on a Website. The content inside the iFrame generally come from another source . The content may be an Advertisement. iFrame behave like  a inline image so it have its own independent scrollbar from the whole web page. A Web designer can change the content of iframe without reload the whole web page. A web page may have many iFrame. a iFrame can be inside of another iFrame.


In Selenium Web Driver we have 3 way to handle Frames.
1) driver.switchTo().frame(int arg0)
2) driver.switchTo().frame(String argo)
3) driver.switchTo().frame(WebElement frameElement)

1) driver.switchTo().frame(int arg0): 
By using this user can select the particular frame by using Index value. The frame count start with "0" if there are more then 1 frame.
Once selenium switch to the frame then the focus of Selenium Web driver will change to Frame
First you can get the total counts of the frame in any web page. Selenium have the method to do it




here you can see that number of frame found = 5. Now suppose you want to switch to the  Frame 1 which have Index 0 so below is the code.



Now you have control over frame 1. This method is useful only when there is one frame because frame position can be changed.

2) driver.switchTo().frame(String argo):
Here Selenium Web driver will select frame by using Id or Name. 
See below Image
Automation Testing, Selenium Web Drivers, Working with Frames




If there is Name and Id is not provided for any iFrame then  this method will not work. For this user need to use 3rd Method.

3) driver.switchTo().frame(WebElement frameElement):
In this method Selenium Web Driver will locate iframe by using previous select WebElement.
See Below Image
Automation Testing, Selenium Web driver, Working With Frame, WebElement





If user want to switch back to the main window then use defaultContent() function
below is the code
 

Comments

Popular posts from this blog

What is API?

In general way, API (Application Programming Interface) is the intermediate software which is useful for two applications to communicate. API is the tool which is used for interaction of two applications. If developer developing any software which have multiple blocks (Modules) than developer use APIs to put them together.

Smoke Testing

In Smoke Testing, Testing team check the key feature or key bugs of the software. Smoke testing ensure that critical functionality of the software is working fine.If key features are not working then it is no needed to test the overall functionality because it is just waste of time. In Smoke Testing, test team check the basic feature of the software and if basic feature is not working it means software is broken very badly and further testing is unnecessary. If Smoke Testing failed then it is declared that build is unstable and revert back to developer team until smoke test is pass.

Guide to Setup Selenium Web Driver

In this Article i am describing you how to setup Selenium Web Driver in your Machine Step 1: First You need to install Java in your Computer. To download the java Click Here