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.

Ad-Hoc Testing

Ad-Hoc Testing is the testing type which is performed without any proper procedure and without any Requirement Specification. Ad-Hoc testing is totally informal testing which have intension to break the application as early as possible and found important defect early.  In Ad-hoc testing tester do not have any test cases so only the users who have very high knowledge regarding the application only they can perform Ad-Hoc Testing.

XPath Expression to locate Web Element

In last article i mentioned you how to locate the Web Element with id, Name, LinkText, Partial LinkText, CSS Selectors, Class Name and Tag Name. We use FireBug add-one to use these 7 locators to locate the Web Element on Web Page. Now we are talking about XPath expression. Which is also a type of Locator. We need FirePath add-ons to use it.