Challenge - 5 Problems
Multiple Pages Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Selenium Python code snippet?
Consider the following code that opens a new tab and switches to it. What will be printed?
Selenium Python
from selenium import webdriver from selenium.webdriver.common.by import By import time browser = webdriver.Chrome() browser.get('https://example.com') original_window = browser.current_window_handle browser.execute_script("window.open('https://example.org', '_blank');") time.sleep(1) for handle in browser.window_handles: if handle != original_window: browser.switch_to.window(handle) break print(browser.title) browser.quit()
Attempts:
2 left
💡 Hint
Remember that the new tab opens 'https://example.org' and the title of that page is 'Example Domain'.
✗ Incorrect
The code opens 'https://example.com' first, then opens a new tab with 'https://example.org'. It switches to the new tab and prints its title, which is 'Example Domain'. Both example.com and example.org have the same title.
❓ assertion
intermediate1:30remaining
Which assertion correctly verifies the switch to a new window?
You have switched to a new window in Selenium. Which assertion correctly checks that the current window handle is not the original one?
Selenium Python
original_window = driver.current_window_handle # code to open new window and switch to it # Which assertion is correct?
Attempts:
2 left
💡 Hint
After switching, the current window handle should be different from the original.
✗ Incorrect
The current window handle after switching should not be the same as the original window handle, so option B is correct.
❓ locator
advanced2:00remaining
Which locator strategy is best to find a link that opens a new tab?
You want to find a link that opens a new tab when clicked. The link has text 'Open New Tab' and attribute target='_blank'. Which locator is best?
Attempts:
2 left
💡 Hint
Use a locator that matches both the attribute and the visible text for precision.
✗ Incorrect
Option A uses XPath to match both the target attribute and the link text, making it the most precise locator.
🔧 Debug
advanced2:30remaining
Why does this Selenium code raise NoSuchWindowException?
Review the code below. Why does it raise NoSuchWindowException when trying to switch windows?
Selenium Python
driver.get('https://example.com') original = driver.current_window_handle # Open new tab driver.execute_script("window.open('https://example.org');") # Incorrect switch for handle in driver.window_handles: if handle == original: driver.switch_to.window(handle) break # Trying to interact with new tab here
Attempts:
2 left
💡 Hint
Check which window handle the code switches to.
✗ Incorrect
The code switches to the original window handle instead of the new one, so when trying to interact with the new tab, it causes NoSuchWindowException.
❓ framework
expert3:00remaining
In a Selenium test framework, how to best handle multiple tabs to ensure tests are reliable?
You design a Selenium test framework that opens multiple tabs during tests. Which practice best ensures tests remain reliable and maintainable?
Attempts:
2 left
💡 Hint
Think about test isolation and resource cleanup.
✗ Incorrect
Switching back to the original window and closing extra tabs prevents side effects and resource leaks, making tests more reliable.