Bird
0
0

Consider the following code snippet:

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

If the browser has 3 tabs open, what will be printed?
AAn exception is thrown
B1
C0
D3
Step-by-Step Solution
Solution:
  1. Step 1: Understand what getWindowHandles() returns

    It returns a set containing all window handles for every open tab or window.
  2. Step 2: Determine the size of the set

    Since there are 3 tabs open, the set will contain 3 unique handles, so size() returns 3.
  3. Final Answer:

    3 -> Option D
  4. Quick Check:

    Number of tabs = size of handles set = 3 [OK]
Quick Trick: Size of getWindowHandles() set equals number of open tabs/windows [OK]
Common Mistakes:
  • Assuming size() returns 1 for current window only
  • Expecting an exception if multiple tabs exist
  • Confusing getWindowHandles() with getWindowHandle()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes