Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to get the current window handle.
Selenium Python
current_handle = driver.[1] Drag options to blanks, or click blank then click option'
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.
✗ Incorrect
The property current_window_handle returns the handle of the current browser window.
2fill in blank
mediumComplete the code to get all open window handles.
Selenium Python
all_handles = driver.[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Adding parentheses to 'window_handles' making it a method call.
Using incorrect method names like 'get_window_handles()'.
✗ Incorrect
The property window_handles returns a list of all open window handles.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using deprecated or incorrect method names like 'switch_to_window'.
Missing the 'switch_to' part before 'window'.
✗ Incorrect
The correct way to switch windows in Selenium Python is driver.switch_to.window(handle).
4fill in blank
hardFill 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'
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.
✗ Incorrect
Use driver.switch_to.window(handle) to switch to each window and driver.window_handles to get all handles.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'switch_window' which is not a valid method.
Not switching to the window before closing it.
✗ Incorrect
Get the original window handle, loop through all handles, switch to each except original, then close.