0
0
Selenium Pythontesting~20 mins

Headless mode for CI in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Headless CI Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Selenium headless mode setup code?
Consider this Python Selenium code snippet that sets up a Chrome browser in headless mode for CI testing. What will be printed after running this code?
Selenium Python
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')

try:
    driver = webdriver.Chrome(options=options)
    driver.get('https://example.com')
    title = driver.title
    print(title)
    driver.quit()
except Exception as e:
    print(f'Error: {e}')
AError: Message: 'chromedriver' executable needs to be in PATH
BNo output (empty string)
CError: WebDriverException: unknown error: Chrome failed to start
DExample Domain
Attempts:
2 left
💡 Hint
Headless mode runs Chrome without opening a window but still loads the page and its title.
assertion
intermediate
1:30remaining
Which assertion correctly verifies the page title in headless mode?
You want to assert that the page title is exactly 'Example Domain' after loading the page in headless mode. Which assertion statement 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')
title = driver.title

# Which assertion below is correct?
Aassert 'Example' in title and 'Domain' not in title
Bassert title != 'Example Domain'
Cassert title == 'Example Domain'
Dassert title == 'example domain'
Attempts:
2 left
💡 Hint
The page title is case sensitive and exactly 'Example Domain'.
🔧 Debug
advanced
2:30remaining
Why does this headless Chrome test fail with a WebDriverException?
This Selenium Python code runs in CI but fails with the error: 'unknown error: Chrome failed to start'. What is the most likely cause?
Selenium Python
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')
# Missing this option causes failure in some CI environments
# options.add_argument('--no-sandbox')

driver = webdriver.Chrome(options=options)
driver.get('https://example.com')
print(driver.title)
driver.quit()
AThe URL 'https://example.com' is unreachable in headless mode
BMissing '--no-sandbox' argument causes Chrome to fail in restricted CI environments
CThe ChromeDriver version is incompatible with Chrome browser
DHeadless mode is not supported on Linux
Attempts:
2 left
💡 Hint
Some CI environments restrict sandboxing, requiring a special Chrome option.
locator
advanced
2:00remaining
Which locator strategy is best for stable element selection in headless CI tests?
You want to select a button with text 'Submit' in a page tested in headless mode. Which locator is most reliable for CI tests?
Adriver.find_element('xpath', "//button[text()='Submit']")
Bdriver.find_element('id', 'submit')
Cdriver.find_element('css selector', 'button.submit-btn')
Ddriver.find_element('class name', 'btn')
Attempts:
2 left
💡 Hint
Text-based XPath is precise if the button text is unique and stable.
framework
expert
3:00remaining
Which CI pipeline step correctly runs Selenium tests in headless mode with Chrome on Linux?
You configure a CI pipeline to run Selenium Python tests with headless Chrome on a Linux runner. Which step setup is correct?
AInstall Chrome and ChromeDriver, run tests with Chrome options '--headless', '--no-sandbox', '--disable-dev-shm-usage'
BRun tests without installing Chrome, rely on default browser, use '--headless' only
CRun tests with GUI enabled, no headless options, and use Xvfb for virtual display
DInstall Firefox and use Selenium with Firefox headless mode instead of Chrome
Attempts:
2 left
💡 Hint
Linux CI runners often require special Chrome options and explicit installation.