Bird
0
0

You wrote this code to run Chrome in headless mode but the browser window still appears. What is the likely mistake?

medium📝 Debug Q14 of 15
Selenium Python - Cross-Browser Testing
You wrote this code to run Chrome in headless mode but the browser window still appears. What is the likely mistake?
from selenium import webdriver
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options=options)
options.add_argument('--headless')
driver.get('https://example.com')
AHeadless mode is not supported on Chrome
BThe headless argument was added after creating the driver, so it was ignored
CYou must call driver.set_headless(True) after creating the driver
DYou forgot to call driver.quit() to close the window
Step-by-Step Solution
Solution:
  1. Step 1: Check order of setting options

    The headless argument must be added to options before creating the driver instance.
  2. Step 2: Identify mistake in code

    Here, options.add_argument('--headless') is called after driver creation, so the driver does not run headless.
  3. Final Answer:

    The headless argument was added after creating the driver, so it was ignored -> Option B
  4. Quick Check:

    Add headless argument before driver creation [OK]
Quick Trick: Add headless option before creating driver instance [OK]
Common Mistakes:
  • Adding headless argument after driver creation
  • Calling non-existent set_headless method
  • Assuming headless unsupported on Chrome

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes