Hello Folks,

This will be last part of “Handling frames in selenium webdriver”.

We know what is frame and how to handle it in selenium webdriver. But I have seen many queries where people is not able to find whether web element is in frame or not. We will see ways of finding if web element is in frame or not in Firefox and chrome browsers.

In Chrome:

Way 1: 

Steps to find:

  1. Right click on web element and click on “Inspect”.
  2. Go to “Elements” tab and see last row (Node structure) as shown in below pic:

3. The highlighted row displays all ancestor nodes with their ID and class attribute values using CSS selector. If you find any frame/iframe node before your desired web element, you can conclude your web element is inside an frame/iframe.

Way 2:

Steps to find:

  1. Mouse hover just near to web element and right click.
  2. If you see context option “View frame source” in context menu, you can conclude desired web element is in frame/iframe.

 

In Firefox:

Firefox browser provides very simple way of identifying if web element in in frame/iframe. Just right click and check context options in context menu. If you are able to find “This Frame” option in context menu, you can conclude web element is in iframe/frame.

I hope, you will be find if web element is in iframe/frame easily in both browsers.

Now we will see sample code with handling frames in selenium webdriver:

Test steps:

  1. Load MainWindow.htm in browser.
  2. Type “Top Frame” in TopFrame input box.
  3. Type “Main Frame” in mainFrame input box.
  4. Type “Bottom Frame” in bottomFrame input box.

Java code:

Output:

 

That’s all. I have covered almost all concepts of frame/iframe. If you have any doubt, feel free to comment below.

If you like my posts, please like, comment, share and subscribe.

#ThanksForReading

#HappySelenium

Leave a Reply