首页 > 解决方案 > selenium.common.exceptions.WebDriverException:消息:无效参数:无法识别的功能:带有 Selenium 和 ChromeDriver 77.0 的 chromeOptions

问题描述

这是我的代码

from selenium import webdriver
driver = webdriver.Chrome('C:\chromedriver_win32\chromedriver')
driver.get('http://google.com')

这是一条错误消息。

Traceback (most recent call last):
  File "D:/project/Python/TEST_selenium/chromedriver_test.py", line 16, in <module>
    driver = webdriver.Chrome(executable_path="C:\chromedriver_win32\chromedriver",chrome_options=chrome_options)
  File "C:\Users\USER\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
    desired_capabilities=desired_capabilities)
  File "C:\Users\USER\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 98, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "C:\Users\USER\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 188, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\USER\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 256, in execute
    self.error_handler.check_response(response)
  File "C:\Users\USER\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: invalid argument: unrecognized capability: chromeOptions

我无法弄清楚为什么这个简单的代码会出现错误。

此代码在一个月前有效。但它现在不起作用。

我已经更新了 chrome 和 chrome 驱动程序,但这并不能解决问题。

我的 chrome 和 chrome 驱动程序版本是 77。

标签: pythonseleniumgoogle-chromeselenium-webdriverselenium-chromedriver

解决方案


欢迎来到 SO!

根据您的问题,我猜您的硒版本已过时。我相信去 Chrome 驱动程序 77 更新了启动行为。

试试看pip install -U selenium是否能解决您的问题。


推荐阅读