Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to open a new browser tab using Selenium.
Selenium Python
driver.[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like open_new_tab() or new_tab()
Trying to call new_window directly on driver without switch_to
✗ Incorrect
The correct method to open a new tab in Selenium Python is driver.switch_to.new_window('tab').
2fill in blank
mediumComplete the code to switch Selenium's focus to the newly opened window.
Selenium Python
driver.switch_to.window(driver.[1][-1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using driver.windows which does not exist
Using driver.tabs which is not a Selenium property
✗ Incorrect
driver.window_handles returns a list of window handles. Using [-1] selects the last opened window.
3fill in blank
hardFix the error in the code to open a new window instead of a tab.
Selenium Python
driver.switch_to.[1]('window')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using new_tab instead of new_window to open a window
Trying to call open_window which is not a Selenium method
✗ Incorrect
The correct method to open a new window is driver.switch_to.new_window('window').
4fill in blank
hardFill both blanks to create a new tab and switch focus to it.
Selenium Python
driver.switch_to.[1]('tab') driver.switch_to.window(driver.[2][-1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using new_tab which is not a valid method
Using windows instead of window_handles to get window handles
✗ Incorrect
First, open a new tab with new_window('tab'), then switch focus using window_handles[-1].
5fill in blank
hardFill all three blanks to open a new window, switch to it, and verify the title.
Selenium Python
driver.switch_to.[1]('window') driver.switch_to.window(driver.[2][-1]) assert driver.title [3] ''
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using != instead of == in the assertion
Using new_tab instead of new_window to open a window
✗ Incorrect
Open a new window with new_window('window'), switch to last handle, then assert title equals ''.