Bird
0
0

Which of the following is the correct way to set Chrome to run in headless mode using Selenium in Python?

easy📝 Syntax Q12 of 15
Selenium Python - Cross-Browser Testing
Which of the following is the correct way to set Chrome to run in headless mode using Selenium in Python?
Aoptions = webdriver.ChromeOptions() options.add_argument('--headless')
Boptions = webdriver.ChromeOptions() options.set_headless(True)
Coptions = webdriver.ChromeOptions() options.headless = True
Doptions = webdriver.ChromeOptions() options.add_option('headless')
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct method to add arguments

    In Selenium Python, add_argument is used to add command line switches like '--headless'.
  2. Step 2: Check each option's syntax

    Only options = webdriver.ChromeOptions() options.add_argument('--headless') uses add_argument('--headless') correctly; others use invalid or non-existent methods.
  3. Final Answer:

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

    Use add_argument('--headless') for headless mode [OK]
Quick Trick: Use add_argument('--headless') to enable headless mode [OK]
Common Mistakes:
  • Using non-existent set_headless method
  • Assigning headless attribute directly
  • Using add_option instead of add_argument

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes