Recall & Review
beginner
What is an iFrame in web testing?
An iFrame is a webpage embedded inside another webpage. It acts like a separate window inside the main page.
Click to reveal answer
beginner
Why do we need to switch to an iFrame in Selenium?
Because elements inside an iFrame are in a different context, Selenium must switch to that frame to interact with those elements.
Click to reveal answer
beginner
How do you switch to an iFrame using Selenium WebDriver in Java?
Use driver.switchTo().frame() method. You can pass the frame's name, index, or WebElement to switch.
Click to reveal answer
intermediate
What happens if you try to access an element inside an iFrame without switching to it first?
Selenium will throw a NoSuchElementException because it cannot see elements inside the iFrame without switching context.
Click to reveal answer
beginner
How do you switch back to the main page from an iFrame in Selenium?
Use driver.switchTo().defaultContent() to return to the main page from any iFrame.
Click to reveal answer
Which Selenium method is used to switch to an iFrame?
✗ Incorrect
driver.switchTo().frame() changes the context to the specified iFrame.
What argument can you NOT pass to switchTo().frame()?
✗ Incorrect
You cannot pass a CSS selector string directly to switchTo().frame(). You must use index, name/id, or WebElement.
After switching to an iFrame, how do you return to the main page?
✗ Incorrect
driver.switchTo().defaultContent() returns to the main page from any iFrame.
What exception is commonly thrown if you try to access an element inside an iFrame without switching?
✗ Incorrect
NoSuchElementException occurs because Selenium cannot find elements inside the iFrame without switching.
If a page has multiple iFrames, how can you switch to the second iFrame?
✗ Incorrect
Frames are zero-indexed, so the second iFrame is at index 1.
Explain why switching to an iFrame is necessary before interacting with its elements in Selenium.
Think about how a webpage inside a webpage works.
You got /4 concepts.
Describe the different ways to switch to an iFrame using Selenium WebDriver in Java.
Remember the method accepts three types of arguments.
You got /4 concepts.