Back to Browse

How to Handle Frames in Selenium WebDriver | Selenium - Java

227 views
Mar 13, 2021
9:56

In this video, I have explained about how we can handle Frames in Selenium WebDriver. Frames are a now deprecated. You might not get chance to work with them unless you are working with a pre-HTML5 web app. Iframes allow the insertion of a document from an entirely different domain and are still commonly used. To interact with any control inside the frame, we will need to first switch to the frame, in a similar way to how we switch windows. WebDriver has three ways of switching to a frame. 1) Using an index 2) Using a name or ID 3) Using a WebElement ****** Using an index ****** It is possible to use the index of the frame to switch to that frame, such as can be queried using window.frames in JavaScript. The first frame on the webpage has index 0. Example: //Switch to the first frame driver.switchTo().frame(0); ****** Using a name or id ****** If webpage frame has id or name inside html. Then the name or ID can be user to identify frame and switched to. Example: //Using id or name driver.switchTo().frame("frame1"); ****** Using a WebElement ****** Switching using a WebElement is the most flexible option. You can find the frame using your preferred selector and switch to it. Example: //Store the web element WebElement frame = driver.findElement(By.id("frame1")); driver.switchTo().frame(frame);

Download

0 formats

No download links available.

How to Handle Frames in Selenium WebDriver | Selenium - Java | NatokHD