options parameter is not detected by ChromeDriverManager() in python

Question:

I try to use both webdriver and ChromeDriverManager at the same time including options but always it returns an error:
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install(), options=options)) TypeError: __init__() got an unexpected keyword argument 'options'

My code is:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options

options = webdriver.ChromeOptions()
# options = Options() # I used this line as well, but it did not work.
options.add_argument("start-maximized")
options.add_argument("--headless")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install(), options=options))
driver.get(url)

What should I do?

Asked By: V.Nouri

||

Answers:

You have to call it like this:

driver = webdriver.Chrome( 
   service=Service(
        ChromeDriverManager().install()
    ),
    options=options
)
Answered By: Giuseppe La Gualano
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.