Bird
0
0

Which of the following is the correct syntax to get all window handles in Selenium Java?

easy📝 Syntax Q12 of 15
Selenium Java - Handling Windows, Frames, and Alerts
Which of the following is the correct syntax to get all window handles in Selenium Java?
AList<String> handles = driver.getWindowHandles();
BString handles = driver.getWindowHandles();
CSet<String> handles = driver.getWindowHandles();
DSet handles = driver.getWindowHandle();
Step-by-Step Solution
Solution:
  1. Step 1: Check the return type of getWindowHandles()

    The method returns a Set of Strings, so the variable must be declared as Set.
  2. Step 2: Verify method name and syntax

    The correct method is getWindowHandles() (plural), and it belongs to the WebDriver instance named driver.
  3. Final Answer:

    Set handles = driver.getWindowHandles(); -> Option C
  4. Quick Check:

    Correct syntax uses Set and getWindowHandles() [OK]
Quick Trick: Use Set for getWindowHandles() return type [OK]
Common Mistakes:
MISTAKES
  • Using List instead of Set for window handles
  • Calling getWindowHandle() instead of getWindowHandles()
  • Assigning to a String instead of a collection

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Java Quizzes