Bird
0
0

In a test, you switch to a popup window, then to an iframe inside that popup. After interacting with elements, what is the correct way to return to the main page context?

hard📝 Application Q9 of 15
Selenium Java - Handling Windows, Frames, and Alerts
In a test, you switch to a popup window, then to an iframe inside that popup. After interacting with elements, what is the correct way to return to the main page context?
Adriver.switchTo().window(mainWindowHandle); driver.switchTo().defaultContent();
Bdriver.switchTo().defaultContent(); driver.switchTo().window(mainWindowHandle);
Cdriver.switchTo().defaultContent(); only
Ddriver.switchTo().window(mainWindowHandle); only
Step-by-Step Solution
Solution:
  1. Step 1: Switch back from iframe to popup window

    Use defaultContent() to exit iframe context inside popup window.
  2. Step 2: Switch from popup window back to main window

    Use window(mainWindowHandle) to switch context back to main page.
  3. Final Answer:

    driver.switchTo().defaultContent(); driver.switchTo().window(mainWindowHandle); -> Option B
  4. Quick Check:

    Window switch after defaultContent for nested contexts [OK]
Quick Trick: Exit frames before switching windows back [OK]
Common Mistakes:
MISTAKES
  • Switching windows before exiting frames
  • Only switching defaultContent without window switch
  • Only switching window without defaultContent

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes