Bird
0
0

Which sequence of Selenium Java commands correctly achieves this?

hard📝 Application Q15 of 15
Selenium Java - Handling Windows, Frames, and Alerts
You have a web page with an iframe named frameA containing a button that opens a new browser window named newWin. You want to click the button inside the iframe, switch to the new window, verify the title is "Welcome", then switch back to the main page. Which sequence of Selenium Java commands correctly achieves this?
Adriver.findElement(By.id("btnOpen")).click(); driver.switchTo().window("newWin"); assertEquals("Welcome", driver.getTitle()); driver.switchTo().frame("frameA");
Bdriver.switchTo().window("newWin"); driver.switchTo().frame("frameA"); driver.findElement(By.id("btnOpen")).click(); assertEquals("Welcome", driver.getTitle()); driver.switchTo().defaultContent();
Cdriver.switchTo().frame("frameA"); driver.findElement(By.id("btnOpen")).click(); driver.switchTo().defaultContent(); driver.switchTo().window("newWin"); assertEquals("Welcome", driver.getTitle()); driver.close(); driver.switchTo().window(driver.getWindowHandles().iterator().next());
Ddriver.switchTo().frame("frameA"); driver.findElement(By.id("btnOpen")).click(); driver.switchTo().window("newWin"); assertEquals("Welcome", driver.getTitle()); driver.switchTo().defaultContent();
Step-by-Step Solution
Solution:
  1. Step 1: Switch to iframe and click button

    Switching to iframe "frameA" is needed to access the button inside it and click it.
  2. Step 2: Switch back to main content before switching window

    After clicking, switch back to main content with defaultContent() before switching to the new window "newWin".
  3. Step 3: Switch to new window, verify title, close it, and return

    Switch to "newWin", check title is "Welcome", close the window, then switch back to the original window using window handles.
  4. Final Answer:

    The sequence correctly handles iframe, window switch, verification, and return. -> Option C
  5. Quick Check:

    Frame switch -> click -> defaultContent -> window switch -> verify -> close -> back [OK]
Quick Trick: Always switch back from iframe before switching windows [OK]
Common Mistakes:
  • Switching windows before switching out of iframe
  • Not switching back to main content before window switch
  • Not closing new window before returning

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes