英文:
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 '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'
答案1
得分: 30
以下是翻译好的部分:
这是由于 selenium
版本 4.10.0
的更改:
https://github.com/SeleniumHQ/selenium/commit/9f5801c82fb3be3d5850707c46c3f8176e3ccd8e
请注意,第一个参数不再是 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
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()
答案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"..\chromedriver.exe")
driver = webdriver.Chrome(service=service)
#It work for me hope selenium version 4.1 chrome 116 latest one
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论