Handling Iframes in Selenium
Posted By : Ankita Sachan | 30-Oct-2017
Iframe is a HTML document inherited inside HTML document defined by tags </iframe></iframe> in DOM because of tags present the iframes can be easily identified.
For Example:
To switch in between the iframes we can use
-
switchTo.frame(int frameNumber): Pass the frame index and driver will switch to that frame.
-
switchTo.frame(string frameNameOrId): Pass the frame element Name or ID and driver will switch to that frame.
-
switchTo.frame(WebElement frameElement): Pass the frame web element and driver will switch to that frame.
Switch to frame by index
Index for an iframe will be the position at will it will be situated in the HTML page. In the example given
To switch in between there two iframes is as follows:
Switch to frames By Name
Looking into the HTML code we come across that
driver.switchTo().frame(“iframe1”).
For example
Switch to frame by ID
Apart from the name attribute in iframe tag ID attribute is also included. Which can be easily used to switch in between
For example:
Switch to frame by WebElement
We can even use the WebElement to switch in between
For example:
Switching back to
Switching back to
Hence all the
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Ankita Sachan
Ankita is a Bright QA engineer and have experience in Manual and Automation Testing. loves to Travel to different places.