这是我的代码
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。
答案 0 :(得分:1)
欢迎您!
根据您的问题,我想您的硒版本已过时。我相信使用Chrome驱动程序77会更新启动行为。
尝试pip install -U selenium
,看看是否可以解决您的问题。
答案 1 :(得分:0)
尝试将ChromeDriver.exe添加到项目所在的文件夹中,或仅尝试driver = webdriver.Chrome()
答案 2 :(得分:0)
此错误消息...
selenium.common.exceptions.WebDriverException: Message: invalid argument: unrecognized capability: chromeOptions
...表示 ChromeDriver 由于无法识别{{1而无法启动/产生新的 WebBrowser ”(即 Chrome浏览器)会话}}。
您需要注意以下几点:
中找到详细的讨论
chromeOptions
(\\)
和原始(\)
开关。(r)
您可以在Error Message: 'chromedriver' executable needs to be PATH
中找到详细的讨论
您的工作代码为:
(.exe)