Bird
0
0

You have a test that opens multiple tabs. You want to switch to the tab with title "Dashboard" and perform actions there. Which approach correctly switches to that window?

hard📝 Application Q15 of 15
Selenium Java - Handling Windows, Frames, and Alerts
You have a test that opens multiple tabs. You want to switch to the tab with title "Dashboard" and perform actions there. Which approach correctly switches to that window?
AClose all windows except the first, then assume it is "Dashboard"
BUse driver.switchTo().window("Dashboard"); directly with the title
CCall driver.getWindowHandle() repeatedly until title is "Dashboard"
DIterate all window handles, switch to each, check title, break when title matches "Dashboard"
Step-by-Step Solution
Solution:
  1. Step 1: Understand window switching by handle

    You cannot switch windows by title directly; you must switch by handle and then check the title.
  2. Step 2: Iterate handles and check titles

    Loop through all window handles, switch to each, check if title equals "Dashboard", then break to stay on that window.
  3. Final Answer:

    Iterate all window handles, switch to each, check title, break when title matches "Dashboard" -> Option D
  4. Quick Check:

    Switch by handle, check title, then stop [OK]
Quick Trick: Switch windows by handle, verify title, then stop [OK]
Common Mistakes:
  • Trying to switch using title as window handle
  • Not looping through all windows
  • Assuming first window is always the target

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes