selenium-webdriver

Navigate between multiple frames

Introduction#

In web pages contain number of frame, selenium consider Frame is seprate window so access the content present into frame need to switch into frame. Many time we need Web structure where we have frame with in frame to navigate within frame windows Selenium provide swithTo() method.

Frame example

<iframe "id="iframe_Login1">

    <iframe "id="iframe_Login2">
  
        <iframe "id="iframe_Login3">

        </iframe>

    </iframe>

</iframe>

To switch into frame in selenium use swithTo() and frame()method.

driver.switchTo().frame(iframe_Login1); driver.switchTo().frame(iframe_Login2); driver.switchTo().frame(iframe_Login3);

To switch back we can use parentFrame() and defaultContest();

parentFrame() : Change focus to the parent context. If the current context is the top level browsing context, the context remains unchanged.

driver.switchTo().parentFrame();

defaultContent() : Selects either the first frame on the page, or the main document when a page contains iframes.

 driver.switchTo().defaultContent();

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow