Challenge - 5 Problems
Page Title & URL 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 Selenium code that opens a webpage and prints the title and current URL. What will be printed?
Selenium Python
from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By service = Service('/path/to/chromedriver') driver = webdriver.Chrome(service=service) driver.get('https://example.com') print(driver.title) print(driver.current_url) driver.quit()
Attempts:
2 left
💡 Hint
Check the exact title text and URL format of https://example.com in a browser.
✗ Incorrect
The page title of https://example.com is exactly 'Example Domain' with capital letters. The URL returned by driver.current_url includes the trailing slash, so it is 'https://example.com/'.
❓ assertion
intermediate1:30remaining
Which assertion correctly verifies the page title after navigation?
You want to check that after navigating to 'https://example.com', the page title is exactly 'Example Domain'. Which assertion is correct?
Selenium Python
from selenium import webdriver from selenium.webdriver.chrome.service import Service service = Service('/path/to/chromedriver') driver = webdriver.Chrome(service=service) driver.get('https://example.com') # Which assertion below is correct?
Attempts:
2 left
💡 Hint
Remember the syntax for equality comparison in Python assertions.
✗ Incorrect
Option A uses the correct equality operator '==' to compare the title string. Option A uses assignment '=' which is invalid in assert. Option A asserts the opposite. Option A uses a method that does not exist on string objects.
❓ locator
advanced2:00remaining
Which locator strategy is best to retrieve the page title element for testing?
You want to locate the HTML element that contains the page title text on 'https://example.com' for validation. Which locator is best?
Attempts:
2 left
💡 Hint
The page title is inside the tag in the section.
✗ Incorrect
The tag is a unique tag inside . Using By.TAG_NAME with 'title' correctly locates it. The other options look for id or class which do not exist on the tag. CSS selector 'head > title' is valid but Selenium does not support locating reliably with CSS selectors.
🔧 Debug
advanced2:30remaining
Why does this Selenium code fail to get the current URL?
This code snippet throws an AttributeError. Identify the cause.
Selenium Python
from selenium import webdriver from selenium.webdriver.chrome.service import Service service = Service('/path/to/chromedriver') driver = webdriver.Chrome(service=service) driver.get('https://example.com') url = driver.get.current_url print(url) driver.quit()
Attempts:
2 left
💡 Hint
Check the difference between methods and attributes on the driver object.
✗ Incorrect
driver.get is a method to navigate to a URL. current_url is an attribute of driver, not of driver.get. So 'driver.get.current_url' is invalid and causes AttributeError.
❓ framework
expert3:00remaining
In a pytest Selenium test, how to correctly assert the page URL after navigation?
Given a pytest test function using Selenium WebDriver, which assertion correctly verifies the URL after navigating to 'https://example.com'?
Selenium Python
import pytest from selenium import webdriver from selenium.webdriver.chrome.service import Service @pytest.fixture def driver(): service = Service('/path/to/chromedriver') driver = webdriver.Chrome(service=service) yield driver driver.quit() def test_example_url(driver): driver.get('https://example.com') # Which assertion below is correct?
Attempts:
2 left
💡 Hint
Use Python string equality operator for exact match in assertions.
✗ Incorrect
Option C uses '==' which correctly compares strings. Option C uses 'is' which compares object identity, not string content, and is incorrect. Option C calls a non-existent method 'equals' on string. Option C calls a non-existent method 'contains' on string.