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

huangapple go评论206阅读模式
英文:

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('/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('/usr/bin/chromedriver', options=chrome_options)

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

Error is:

TypeError: WebDriver.__init__() got multiple values for argument &#39;options&#39;

`

The code is:

chrome_options = Options()
chrome_options.add_argument(&#39;--headless&#39;)
chrome_options.add_argument(&#39;--no-sandbox&#39;)
chrome_options.add_argument(&#39;--disable-dev-shm-usage&#39;)

browser = webdriver.Chrome(r&#39;/usr/bin/chromedriver&#39;, options=chrome_options)

This is the error:

TypeError                                 Traceback (most recent call last)
&lt;ipython-input-5-9a7e59e392ae&gt; in &lt;cell line: 6&gt;()
      4 chrome_options.add_argument(&#39;--headless&#39;)
      5 
----&gt; 6 browser = webdriver.Chrome(r&#39;/usr/bin/chromedriver&#39;, options=chrome_options)

TypeError: WebDriver.__init__() got multiple values for argument &#39;options&#39;

答案1

得分: 30

以下是翻译好的部分:

这是由于 selenium 版本 4.10.0 的更改:
https://github.com/SeleniumHQ/selenium/commit/9f5801c82fb3be3d5850707c46c3f8176e3ccd8e

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

请注意,第一个参数不再是 executable_path,而是 options。(这就是为什么它抱怨您传递了两次的原因。)

如果您想传递一个 executable_path,现在您需要使用 service 参数。

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()
英文:

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

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

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&#39;/usr/bin/chromedriver&#39;)
options = webdriver.ChromeOptions()
options.add_argument(&#39;--headless&#39;)
options.add_argument(&#39;--no-sandbox&#39;)
options.add_argument(&#39;--disable-dev-shm-usage&#39;)
driver = webdriver.Chrome(service=service, options=options)
# ...
driver.quit()

答案2

得分: 1

#解决Selenium驱动程序不工作的有效方法
-------------------------------------------------------------------
```python
from selenium import webdriver
from selenium.webdriver.chrome.service import Service

#请仔细检查是否在Chromedriver路径的末尾添加了.exe

service = Service(executable_path=r"..\chromedriver.exe")
driver = webdriver.Chrome(service=service)

#这对我有用,希望适用于Selenium版本4.1和Chrome 116最新版本


<details>
<summary>英文:</summary>

#Working solution for selenium driver not working 
-------------------------------------------------------------------
```python
from selenium import webdriver

from selenium.webdriver.chrome.service import Service

Please cross check if you add .exe at the end of your Chromedriver path

service = Service(executable_path=r&quot;..\chromedriver.exe&quot;) 

driver = webdriver.Chrome(service=service)

#It work for me hope selenium version 4.1 chrome 116 latest one

huangapple
  • 本文由 发表于 2023年6月8日 12:11:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76428561.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定