How to Handle Multiple Frames in Selenium WebDriver

Here is the example of multiple frames in a web page and how to interact with them.

There is three overloaded frame () methods, to switch to the frame.

methods details

How to decide when to use which method???

If it’s a static web page and so frame elements are, then zero-based index [frame(int index)] locating strategy can be used to locate the frame.

If the frame element is having unique name or id attribute, then frame could be located with its name or id attribute. [frame(java.lang.StringnameOrId)]

If frame is not located either with above mechanism, then it can be located with it’s web element. [frame (WebElementframeElement)]

Here is an example:-

0 based index is used here.

 

 

 

After working with the frame, main important is to come back to the web page. if we don’t switch back to the default page, driver will throw an exception. You’ll have to use defaultContent() method.

 

defaultContent

 

Comments

  1. By Hussain Ahmed

    Reply

  2. By Jessianut

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *