Challenge - 5 Problems
Pop-up Pro
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 code snippet?
Consider the following Selenium Python code that handles a simple alert pop-up. What will be printed after execution?
Selenium Python
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.alert import Alert # Assume driver is already initialized and navigated to page alert_button = driver.find_element(By.ID, 'alertBtn') alert_button.click() alert = Alert(driver) alert_text = alert.text alert.accept() print(alert_text)
Attempts:
2 left
💡 Hint
Remember that Alert(driver) switches context to the alert pop-up and .text reads its message.
✗ Incorrect
The Alert object allows reading the alert's text before accepting it. The code prints the alert's message.
❓ assertion
intermediate1:30remaining
Which assertion correctly verifies a confirmation pop-up was accepted?
After clicking a button that triggers a confirmation pop-up, you accept it. Which assertion correctly checks that the pop-up was accepted by verifying the page text?
Selenium Python
from selenium.webdriver.common.by import By # After accepting confirmation pop-up result_text = driver.find_element(By.ID, 'result').text
Attempts:
2 left
💡 Hint
Accepting confirmation usually changes page text to indicate confirmation.
✗ Incorrect
The page updates to show 'Confirmed' after accepting the pop-up, so the assertion checks for that text.
❓ locator
advanced1:30remaining
Which locator is best to find a button that opens a new browser window?
You want to locate a button that opens a new window. The button has a unique aria-label 'Open new window'. Which locator is best practice?
Attempts:
2 left
💡 Hint
Use semantic attributes for accessibility and uniqueness.
✗ Incorrect
Using aria-label with CSS selector is reliable and accessible for locating the button.
🔧 Debug
advanced2:00remaining
Why does this Selenium code fail to switch to the new window?
This code clicks a button to open a new window, then tries to switch to it. Why does it fail?
Selenium Python
original_window = driver.current_window_handle button = driver.find_element(By.ID, 'openWindowBtn') button.click() # Attempt to switch for handle in driver.window_handles: if handle != original_window: driver.switch_to.window(handle) break print(driver.title)
Attempts:
2 left
💡 Hint
New windows may take time to open; immediate switch can fail.
✗ Incorrect
Without waiting, the new window handle may not appear yet, causing switch to fail.
❓ framework
expert2:30remaining
Which test framework feature best handles flaky pop-up alerts in Selenium tests?
Pop-up alerts sometimes appear with delay causing test failures. Which framework feature best handles this to make tests stable?
Attempts:
2 left
💡 Hint
Waiting specifically for alerts is more reliable than global waits.
✗ Incorrect
Explicit waits for alert presence ensure code interacts only when alert is ready, reducing flakiness.