Bird
0
0

Identify the error in this code snippet for running Chrome headless: from selenium import webdriver options = webdriver.ChromeOptions() options.add_argument('headless') driver = webdriver.Chrome(options=options) driver.get('https://example.com')

medium📝 Debug Q6 of 15
Selenium Python - Cross-Browser Testing
Identify the error in this code snippet for running Chrome headless: from selenium import webdriver options = webdriver.ChromeOptions() options.add_argument('headless') driver = webdriver.Chrome(options=options) driver.get('https://example.com')
AChromeOptions cannot be used with Chrome driver
BNo error, code runs correctly
Cdriver.get() is not allowed in headless mode
DThe argument 'headless' is missing the required '--' prefix
Step-by-Step Solution
Solution:
  1. Step 1: Check argument format for headless

    The argument must be '--headless' with two dashes, not 'headless' alone.
  2. Step 2: Verify other parts

    ChromeOptions is correct, driver.get() works in headless mode. So only the argument is wrong.
  3. Final Answer:

    The argument 'headless' is missing the required '--' prefix -> Option D
  4. Quick Check:

    Use '--headless' not 'headless' [OK]
Quick Trick: Headless argument needs '--' prefix [OK]
Common Mistakes:
  • Using 'headless' instead of '--headless'
  • Thinking driver.get() fails in headless
  • Believing ChromeOptions is invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes