Bird
0
0

Which of the following is the correct way to enable headless mode in Selenium with Python for Chrome?

easy📝 Syntax Q12 of 15
Selenium Python - CI/CD Integration
Which of the following is the correct way to enable headless mode in Selenium with Python for Chrome?
Aoptions = webdriver.ChromeOptions() options.headless = True browser = webdriver.Chrome(options=options)
Boptions = webdriver.ChromeOptions() options.add_argument('--headless') browser = webdriver.Chrome(options=options)
Cbrowser = webdriver.Chrome() browser.headless = True
Dbrowser = webdriver.Chrome() browser.set_headless(True)
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct syntax for headless Chrome

    In Selenium Python, headless mode is enabled by adding the argument '--headless' to ChromeOptions.
  2. Step 2: Check each option for correctness

    options = webdriver.ChromeOptions() options.add_argument('--headless') browser = webdriver.Chrome(options=options) correctly uses options.add_argument('--headless') and passes options to Chrome driver.
  3. Final Answer:

    options = webdriver.ChromeOptions() options.add_argument('--headless') browser = webdriver.Chrome(options=options) -> Option B
  4. Quick Check:

    Use add_argument('--headless') to enable headless mode [OK]
Quick Trick: Use add_argument('--headless') on options for headless Chrome [OK]
Common Mistakes:
  • Setting options.headless = True (not supported)
  • Trying to set headless directly on browser instance
  • Using non-existent set_headless method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes