Challenge - 5 Problems
URL Opening 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 code snippet?
Consider the following Python Selenium code that opens a URL and prints the current URL.
What will be printed?
What will be printed?
Selenium Python
from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.options import Options options = Options() options.add_argument('--headless') service = Service() driver = webdriver.Chrome(service=service, options=options) driver.get('https://example.com') print(driver.current_url) driver.quit()
Attempts:
2 left
💡 Hint
The browser normalizes URLs and often adds a trailing slash for root domains.
✗ Incorrect
When Selenium opens 'https://example.com', the browser adds a trailing slash, so current_url returns 'https://example.com/'.
❓ assertion
intermediate1:30remaining
Which assertion correctly verifies the page title after opening a URL?
You want to check that after opening 'https://example.com', the page title is exactly 'Example Domain'. Which assertion is correct?
Selenium Python
driver.get('https://example.com') # Which assertion below is correct?
Attempts:
2 left
💡 Hint
Use '==' to compare values in Python assertions.
✗ Incorrect
Option B correctly uses '==' to compare the title string. Option B uses assignment (=) which is invalid in assert. Option B asserts the opposite. Option B uses a method that does not exist on string.
❓ locator
advanced1:30remaining
Which locator is best to find the main heading after opening a URL?
After opening 'https://example.com', you want to locate the main heading <h1> element. Which locator is best practice?
Selenium Python
driver.get('https://example.com') # Choose the best locator to find the main heading
Attempts:
2 left
💡 Hint
Use simple and direct locators when possible.
✗ Incorrect
Option A uses the tag name locator directly for the h1 element, which is simple and reliable here. Option A and C depend on div structure which may change. Option A fails because no element has id 'main-heading'.
🔧 Debug
advanced2:00remaining
Why does this Selenium code raise an error when opening a URL?
Examine the code below. It raises an error when trying to open the URL. What is the cause?
Selenium Python
from selenium import webdriver driver = webdriver.Chrome() driver.get('htp://example.com') driver.quit()
Attempts:
2 left
💡 Hint
Check the URL spelling carefully.
✗ Incorrect
The URL scheme 'htp' is a typo and invalid. Selenium raises an error because it cannot navigate to an invalid URL.
❓ framework
expert3:00remaining
In a pytest Selenium test, which fixture setup ensures the browser opens the URL before each test?
You want to write a pytest fixture that opens 'https://example.com' before each test and closes the browser after. Which fixture code is correct?
Attempts:
2 left
💡 Hint
Pytest fixtures are usually synchronous unless using async tests.
✗ Incorrect
Option D correctly defines a synchronous fixture that opens the URL before yielding the driver and quits after. Options B and C use 'async def' which is invalid here. Option D does not open the URL before yielding.