Bird
0
0

Given the code:

medium📝 Predict Output Q4 of 15
Selenium Java - Handling Windows, Frames, and Alerts
Given the code:
Set handles = driver.getWindowHandles();
System.out.println(handles.size());

What will be the output if there are 5 browser windows currently open?
A4
B5
C1
D0
Step-by-Step Solution
Solution:
  1. Step 1: Understand what getWindowHandles() returns

    It returns a Set containing all window handles.
  2. Step 2: Size of the Set

    The size of the Set equals the number of open windows.
  3. Step 3: Given 5 windows open

    The size will be 5.
  4. Final Answer:

    5 -> Option B
  5. Quick Check:

    Set size equals open windows count [OK]
Quick Trick: Size of getWindowHandles() = number of open windows [OK]
Common Mistakes:
MISTAKES
  • Assuming it returns number of tabs minus one
  • Confusing with getWindowHandle() which returns one handle
  • Expecting output to be zero or one

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes