Bird
0
0

Which of the following code snippets correctly assigns all window handles to a variable named windowHandles in Selenium Java?

easy📝 Syntax Q3 of 15
Selenium Java - Handling Windows, Frames, and Alerts
Which of the following code snippets correctly assigns all window handles to a variable named windowHandles in Selenium Java?
ASet<String> windowHandles = driver.getWindowHandles();
BList<String> windowHandles = driver.getWindowHandles();
CString windowHandles = driver.getWindowHandles();
DMap<String, String> windowHandles = driver.getWindowHandles();
Step-by-Step Solution
Solution:
  1. Step 1: Check the return type of getWindowHandles()

    The method returns a Set of Strings.
  2. Step 2: Match the variable type

    Only Set<String> matches the return type.
  3. Final Answer:

    Set<String> windowHandles = driver.getWindowHandles(); -> Option A
  4. Quick Check:

    Set matches return type [OK]
Quick Trick: Use Set for getWindowHandles() [OK]
Common Mistakes:
  • Using List instead of Set
  • Assigning to String variable
  • Using Map which is incorrect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes