0
0
Selenium Pythontesting~10 mins

Why multi-window scenarios need switching in Selenium Python - Test Your Understanding

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

Complete the code to switch to the new browser window.

Selenium Python
driver.switch_to.[1](window_handle)
Drag options to blanks, or click blank then click option'
Aframe
Btab
Calert
Dwindow
Attempts:
3 left
💡 Hint
Common Mistakes
Using switch_to.frame instead of switch_to.window
Trying to switch without specifying window handle
2fill in blank
medium

Complete the code to get all open window handles.

Selenium Python
handles = driver.[1]
Drag options to blanks, or click blank then click option'
Acurrent_window_handle
Bget_window_handle
Cwindow_handles
Dall_windows
Attempts:
3 left
💡 Hint
Common Mistakes
Using current_window_handle which returns only one handle
Using a non-existent attribute like all_windows
3fill in blank
hard

Fix the error in switching to a new window by completing the code.

Selenium Python
new_window = [handle for handle in driver.[1] if handle != driver.current_window_handle][0]
driver.switch_to.window(new_window)
Drag options to blanks, or click blank then click option'
Acurrent_window_handle
Bwindow_handles
Cget_window_handles
Dhandles
Attempts:
3 left
💡 Hint
Common Mistakes
Using current_window_handle which is a single handle
Using a non-existent method get_window_handles
4fill in blank
hard

Fill both blanks to close the current window and switch back to the original window.

Selenium Python
driver.[1]()
driver.switch_to.[2](original_window)
Drag options to blanks, or click blank then click option'
Aclose
Bquit
Cwindow
Dframe
Attempts:
3 left
💡 Hint
Common Mistakes
Using quit() which closes the whole browser
Switching to frame instead of window
5fill in blank
hard

Fill all three blanks to open a new window, switch to it, and verify the title.

Selenium Python
driver.[1]('window')
new_handle = [h for h in driver.[2] if h != driver.current_window_handle][0]
driver.switch_to.[3](new_handle)
assert 'New Page' in driver.title
Drag options to blanks, or click blank then click option'
Aswitch_to.new_window
Bwindow_handles
Cwindow
Dswitch_to.window
Attempts:
3 left
💡 Hint
Common Mistakes
Using driver.get() to open new window
Confusing switch_to.window with switch_to.frame