0
0
Selenium Pythontesting~10 mins

Window handles in Selenium Python - 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 the current window handle.

Selenium Python
current_handle = driver.[1]
Drag options to blanks, or click blank then click option'
Acurrent_window_handle
Bcurrent_window
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'current_window' which is not a valid property.
Trying to access window handles as a method with parentheses.
2fill in blank
medium

Complete the code to get all open window handles.

Selenium Python
all_handles = driver.[1]
Drag options to blanks, or click blank then click option'
Awindow_handles
Bwindow_handles()
Cget_window_handles()
Dhandles
Attempts:
3 left
💡 Hint
Common Mistakes
Adding parentheses to 'window_handles' making it a method call.
Using incorrect method names like 'get_window_handles()'.
3fill in blank
hard

Fix the error in switching to a new window handle.

Selenium Python
driver.[1](new_handle)
Drag options to blanks, or click blank then click option'
Aswitch_to_window
Bswitch_to.window
CswitchToWindow
Dswitch_window
Attempts:
3 left
💡 Hint
Common Mistakes
Using deprecated or incorrect method names like 'switch_to_window'.
Missing the 'switch_to' part before 'window'.
4fill in blank
hard

Fill both blanks to create a dictionary of window handles and their titles.

Selenium Python
handles_titles = {handle: driver.switch_to.[1](handle).title for handle in driver.[2]
Drag options to blanks, or click blank then click option'
Awindow
Bwindow_handles
Ccurrent_window_handle
Dswitch_window
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'current_window_handle' instead of 'window_handles' for all handles.
Using 'switch_window' which is not a valid method.
5fill in blank
hard

Fill all three blanks to close all windows except the original one.

Selenium Python
original = driver.[1]
for handle in driver.[2]:
    if handle != original:
        driver.switch_to.[3](handle)
        driver.close()
Drag options to blanks, or click blank then click option'
Acurrent_window_handle
Bwindow_handles
Cwindow
Dswitch_window
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'switch_window' which is not a valid method.
Not switching to the window before closing it.