iFrame:
iFrame in Selenium Webdriver is a web page or an inline frame which is embedded in another web page or an HTML document embedded inside another HTML document.
How to Handle Frames in Selenium using WebDriver Commands
Basically, we can switch over the elements and handle frames in Selenium using 3 ways.
By Index
By Name or Id
By Web Element
Method 1: Switch to the frame by index
Index is one of the attributes for frame handling in Selenium through which we can switch to it.
Index of the iframe starts with ‘0’.
Suppose if there are 100 frames in page, we can switch to frame in Selenium by using index.
driver.switchTo().frame(0);
driver.switchTo().frame(1);
Method 2: Switch to the frame by Name or ID
Name and ID are attributes for handling frames in Selenium through which we can switch to the iframe.
driver.switchTo().frame("iframe1");
driver.switchTo().frame("id of the element");
Method 3: Switch to the frame by Web Element
We can even switch to the iframe using web element .
driver.switchTo().frame(WebElement);
How to switch back to the Main Frame
We have to come out of the iframe.
To move back to the parent frame, you can either use switchTo().parentFrame() or if you want to get back to the main (or most parent) frame, you can use switchTo().defaultContent();
driver.switchTo().parentFrame();
driver.switchTo().defaultContent();
Watch video Handling iframe in Selenium WebDriver online without registration, duration hours minute second in high quality. This video was added by user Programming with Pallavi 14 July 2023, don't forget to share it with your friends and acquaintances, it has been viewed on our site 55 once and liked it 2 people.