Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: WebDriver.__init__() got multiple values for argument 'options'

Error is:

TypeError: WebDriver.__init__() got multiple values for argument 'options'

`

The code is:

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')

browser = webdriver.Chrome(r'/usr/bin/chromedriver', options=chrome_options)

This is the error:

TypeError                                 Traceback (most recent call last)
<ipython-input-5-9a7e59e392ae> in <cell line: 6>()
      4 chrome_options.add_argument('--headless')
      5 
----> 6 browser = webdriver.Chrome(r'/usr/bin/chromedriver', options=chrome_options)

TypeError: WebDriver.__init__() got multiple values for argument 'options'
like image 967
Tor Avatar asked Sep 05 '25 17:09

Tor


1 Answers

This is due to changes in selenium 4.10.0: https://github.com/SeleniumHQ/selenium/commit/9f5801c82fb3be3d5850707c46c3f8176e3ccd8e

Changes_in_selenium_4_10_0

Note that the first argument is no longer executable_path, but options. (That's why it complains that you're passing it in twice.)

If you want to pass in an executable_path, you'll have to use the service arg now.

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

service = Service(executable_path=r'/usr/bin/chromedriver')
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(service=service, options=options)
# ...
driver.quit()
like image 65
Michael Mintz Avatar answered Sep 07 '25 07:09

Michael Mintz