Selenium Interview Question 22 – How to handle frames in WebDriver?

Selenium Interview Question 22 – How to handle frames in WebDriver?

<<Previous Question       <<1500 Plus Interview Questions>>       Next Question>>

How to handle frames in WebDriver?

Watch the answer for this Selenium Interview Question in a detailed manner in the below youtube video:

Note: Don’t forget to subscribe to my Youtube channel here: Click here

Notes used for explanation in this Youtube video are provided after the video:

Notes used in the above Youtube Video:

Provide the following points while explaining this interview question:

  • > Frame is a web page which is embedded into another web page
  • > ‘NoSuchElementException’ will be displayed on trying to find the web element which is displayed in an iframe
  • > We have to switch to the respective frame in which the web element is available, before performing operations on the web element.
    • driver.switchTo().frame() is the predefined command of Selenium WebDriver interface for switching to the respective frames
    • – The following are the different ways we can switch to the frames:
      • >> Using driver.switchTo().frame(“IdValueOfFrame“);
      • >> Using driver.switchTo().frame(WebElementOfFrame);
      • >> Using driver.switchTo().frame(FrameIndex);

To add more value to your answer:

  • > driver.switchTo().defaultContent() will be used to switch back to the default page from the frame
  • > Inorder to switch to a child frame, we have to first switch to the parent frame and then switch to the child frame
  • > Inorder to switch from one frame to another frame at the same level on the page, we have to switch to the main page and then switch to the required frame
    • – Frame to Frame switching is not possible, if the other frame is not a child frame.

Next Steps:

  • > For more Selenium Interview Questions and answers, continue to the next post (Click on Next Post link below)
  • > Check complete Selenium Interview Questions list here (Click here)

Please leave your questions/comments/feedback below.

Happy Learning ?

About Me > Arun Motoori

<<Previous Question       <<1500 Plus Interview Questions>>       Next Question>>

On a mission to contribute to the Software Testing Community in all possible ways.


Comments (4)

  • Hi Arun,

    How many frames are there in a page, how will understand?

    • Author

      Hi Saheli,

      Find the below program for finding the number of frames in a page:

      package qafox.HandlingFrames;

      import org.openqa.selenium.By;
      import org.openqa.selenium.WebDriver;

      import io.github.bonigarcia.wdm.WebDriverManager;

      public class Demo1 {

      public static void main(String[] args) {

      WebDriver driver = new ChromeDriver();

      int iframesCount = driver.findElements(By.tagName(“iframe”)).size();





  • Your are explaining good way.


Leave a Reply

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

For FREE Testing Tutorials & Videos

Open chat
Contact Us on Whatsapp