Challenge - 5 Problems
Headless Browser Mastery
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 headless browser code?
Consider the following Python Selenium code snippet that runs a headless Chrome browser and fetches the page title. What will be printed?
Selenium Python
from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.add_argument('--headless') driver = webdriver.Chrome(options=options) driver.get('https://example.com') print(driver.title) driver.quit()
Attempts:
2 left
💡 Hint
The page title is the text inside the tag of the loaded page.
✗ Incorrect
The code opens https://example.com in a headless Chrome browser and prints the page title, which is 'Example Domain'.
❓ assertion
intermediate2:00remaining
Which assertion correctly verifies the page title in headless mode?
You want to assert that the page title is exactly 'Welcome Page' after loading a page in headless mode. Which assertion is correct?
Selenium Python
from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.add_argument('--headless') driver = webdriver.Chrome(options=options) driver.get('https://example.com/welcome') # Which assertion below is correct?
Attempts:
2 left
💡 Hint
Check the correct Python syntax for string equality and attribute access.
✗ Incorrect
The page title is accessed as a string attribute driver.title. The correct way to assert equality is 'assert driver.title == "Welcome Page"'.
🔧 Debug
advanced2:30remaining
Why does this headless browser test fail to find the element?
This Selenium test runs in headless mode but fails to find the element with id 'submit-btn'. What is the likely cause?
Selenium Python
from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.by import By options = Options() options.add_argument('--headless') driver = webdriver.Chrome(options=options) driver.get('https://example.com/form') submit_button = driver.find_element(By.ID, 'submit-btn') submit_button.click() driver.quit()
Attempts:
2 left
💡 Hint
Check if the element is inside a frame or iframe that requires switching context.
✗ Incorrect
In headless mode, the page renders normally including iframes. If the element is inside an iframe, Selenium must switch to that iframe before locating the element.
❓ framework
advanced2:30remaining
Which setup correctly initializes a headless Firefox browser in pytest fixture?
You want to create a pytest fixture that provides a headless Firefox WebDriver instance. Which code snippet is correct?
Attempts:
2 left
💡 Hint
Check how to set headless mode for Firefox using the Options class.
✗ Incorrect
For Firefox, setting options.headless = True enables headless mode. Using options.add_argument('--headless') is not correct for Firefox. driver.quit() properly closes the browser.
🧠 Conceptual
expert3:00remaining
What is a key limitation of headless browser testing compared to headed mode?
Which of the following is a common limitation when running tests in headless browser mode compared to headed (normal) mode?
Attempts:
2 left
💡 Hint
Think about differences in rendering and user interface behavior between headless and headed browsers.
✗ Incorrect
Headless browsers may render pages slightly differently, especially with animations or complex CSS, which can cause tests to fail even if the headed browser works fine.