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

Why Jmeter is best option for Performance Testing?

There are multiple tools in market for performance testing of any software but Jmeter is the best solution among all of them due to some reason listed below 1) Jmeter is the open source application so users who use this application will not to pay anything. 2) You can use Jmeter for performance of any web application,  Databases and Web Services (REST and SOAP APIs). 3) Jmeter have the user friendly UI component so it is very easy to use. 4) Jmeter can be used to simulate to put maximum number of concurrent users on a server, network or object to test its strength or to analyze overall performance under different load types. 5) Jmeter also use for functional testing for static( JavaScript and HTML) and dynamic( JSP, Servlets and AJAX) resources. 6) Jmeter provides Verity of graphical representations for performance report so it is easy to understand.

How You Can Test Database?

Now we know the Database Testing which you can learn in my last article. In this article we will discuss about the steps that need to following to test any Database. Database Tester should have some basic knowledge regarding SQL Command like DDL (create/drop),  DML (Insert/Delete/Update) and DCL (Grant/Revoke).

Causes of Software Defects

It is practically impossible that developer develop a bug free software and that software we can deliver without Testing. If the complexity of the software increased then there must be bugs that can harm the users who will use that software.