Bird
0
0

What is wrong with this code snippet?

medium📝 Debug Q14 of 15
Selenium Java - Handling Windows, Frames, and Alerts
What is wrong with this code snippet?
driver.switchTo().frame("frame1");
driver.findElement(By.id("button")).click();
driver.switchTo().frame("frame2");
driver.findElement(By.id("link")).click();
AYou should use driver.switchTo().parentFrame() instead of frame().
BYou cannot switch to iframe by name.
CThe code is correct and will work fine.
DYou must switch back to defaultContent() before switching to another iframe.
Step-by-Step Solution
Solution:
  1. Step 1: Understand iframe switching rules

    Switching directly from one iframe to another without returning to main page is not allowed.
  2. Step 2: Correct way to switch between iframes

    You must first switch back to main page using defaultContent(), then switch to the second iframe.
  3. Final Answer:

    You must switch back to defaultContent() before switching to another iframe. -> Option D
  4. Quick Check:

    Switch frames via defaultContent() between iframes [OK]
Quick Trick: Always return to main page before switching to another iframe [OK]
Common Mistakes:
  • Switching directly between iframes without defaultContent()
  • Confusing parentFrame() with defaultContent()
  • Assuming switching by name is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes