0
0
Selenium Javatesting~10 mins

Window handles (getWindowHandles) in Selenium Java - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to get all window handles.

Selenium Java
Set<String> handles = driver.[1]();
Drag options to blanks, or click blank then click option'
AgetWindowHandles
BgetWindowHandle
CgetHandles
DwindowHandles
Attempts:
3 left
💡 Hint
Common Mistakes
Using getWindowHandle() which returns only the current window handle.
Using incorrect method names like getHandles or windowHandles.
2fill in blank
medium

Complete the code to switch to a new window handle.

Selenium Java
for (String handle : driver.[1]()) {
    driver.switchTo().window(handle);
}
Drag options to blanks, or click blank then click option'
AgetWindowHandle
BgetHandles
CgetWindowHandles
DwindowHandles
Attempts:
3 left
💡 Hint
Common Mistakes
Using getWindowHandle() which returns only one handle.
Trying to switch without iterating over all handles.
3fill in blank
hard

Fix the error in the code to correctly get window handles.

Selenium Java
Set<String> handles = driver.[1];
Drag options to blanks, or click blank then click option'
AwindowHandles()
BgetWindowHandles()
CgetWindowHandles
DgetWindowHandle()
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting parentheses after method name.
Using singular getWindowHandle() instead of plural.
4fill in blank
hard

Fill both blanks to iterate over window handles and print each handle.

Selenium Java
for ([1] handle : driver.[2]()) {
    System.out.println(handle);
}
Drag options to blanks, or click blank then click option'
AString
Bint
CgetWindowHandles
DgetWindowHandle
Attempts:
3 left
💡 Hint
Common Mistakes
Using int instead of String for the handle variable.
Using getWindowHandle() which returns only one handle.
5fill in blank
hard

Fill all three blanks to switch to a new window and close it.

Selenium Java
Set<String> handles = driver.[1]();
for ([2] handle : handles) {
    if (!handle.equals(driver.[3]())) {
        driver.switchTo().window(handle);
        driver.close();
    }
}
Drag options to blanks, or click blank then click option'
AgetWindowHandles
BString
CgetWindowHandle
DwindowHandle
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method names or missing parentheses.
Using wrong variable types for handles.