Bird
0
0

Identify the error in the following code snippet:

medium📝 Debug Q6 of 15
Selenium Java - Handling Windows, Frames, and Alerts
Identify the error in the following code snippet:
Set windows = driver.getWindowHandles();
for(String win : windows) {
  driver.switchTo().window();
  System.out.println(win);
}
AIncorrect loop variable type
BPrinting window handle instead of title
CUsing getWindowHandles() instead of getWindowHandle()
DMissing window handle argument in switchTo().window() method
Step-by-Step Solution
Solution:
  1. Step 1: Check method usage

    The method switchTo().window() requires a window handle argument to specify which window to switch to.
  2. Step 2: Identify missing argument

    The code calls switchTo().window() without passing win, causing a compile-time error.
  3. Final Answer:

    Missing window handle argument in switchTo().window() method -> Option D
  4. Quick Check:

    switchTo().window() needs handle argument [OK]
Quick Trick: Always pass window handle to switchTo().window(handle) [OK]
Common Mistakes:
  • Forgetting to pass the window handle argument
  • Confusing getWindowHandles() with getWindowHandle()
  • Printing handle instead of title is not an error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes