0
0
Selenium Pythontesting~10 mins

Handling multiple pages 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 switch to the new browser tab after clicking a link.

Selenium Python
driver.find_element(By.LINK_TEXT, 'Open new tab').click()
driver.[1](driver.window_handles[1])
Drag options to blanks, or click blank then click option'
Aswitch_to.window
Bget
Cfind_element
Dclose
Attempts:
3 left
💡 Hint
Common Mistakes
Using driver.get() instead of switching windows
Trying to find elements before switching windows
Closing the current window instead of switching
2fill in blank
medium

Complete the code to close the current tab and switch back to the original tab.

Selenium Python
driver.close()
driver.[1](driver.window_handles[0])
Drag options to blanks, or click blank then click option'
Aquit
Bfind_element
Cswitch_to.window
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Using driver.get() which loads a URL instead of switching windows
Calling driver.quit() which closes the entire browser
Not switching back after closing the tab
3fill in blank
hard

Fix the error in the code to correctly switch to the last opened window.

Selenium Python
last_window = driver.window_handles[-1]
driver.[1](last_window)
Drag options to blanks, or click blank then click option'
Aget
Bswitch_to.window
Cfind_element
Dclose
Attempts:
3 left
💡 Hint
Common Mistakes
Using driver.get() which loads a URL instead of switching windows
Trying to find elements before switching windows
Closing the window instead of switching
4fill in blank
hard

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

Selenium Python
windows = {handle: driver.[1](handle).title for handle in driver.[2]
Drag options to blanks, or click blank then click option'
Aswitch_to.window
Bwindow_handles
Ccurrent_window_handle
Dfind_element
Attempts:
3 left
💡 Hint
Common Mistakes
Using current_window_handle which is only one window
Trying to find elements instead of switching windows
Not switching windows before getting title
5fill in blank
hard

Fill all three blanks to switch to each window, print its title, and then switch back to the original window.

Selenium Python
original = driver.[1]
for handle in driver.[2]:
    driver.[3](handle)
    print(driver.title)
driver.switch_to.window(original)
Drag options to blanks, or click blank then click option'
Acurrent_window_handle
Bwindow_handles
Cswitch_to.window
Dclose
Attempts:
3 left
💡 Hint
Common Mistakes
Not saving the original window handle
Using driver.close() instead of switching windows
Not switching back to the original window