SessionNotCreatedException:消息:未创建会话:虽然已安装Chrome v74,但此版本的ChromeDriver仅支持Chrome版本74

问题描述 投票:0回答:1

我开始在python中使用selenium,当我尝试运行此代码时,它只是弹出一个错误,这个版本的chromedriver只支持版本74的chrome,但我已经从这里下载了版本74:https://chromedriver.storage.googleapis.com/index.html?path=74.0.3729.6/

我试图运行的代码:

import selenium
from selenium import webdriver

driver = webdriver.Chrome()
driver.get('https://stackoverflow.com')
driver.quit()

错误:

Traceback (most recent call last):
  File "c:/Users/Main/Desktop/Python web bot/Bot 
code/selenium_training.py", line 3, in <module>
driver = webdriver.Chrome()
  File "C:\Users\Main\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
  File "C:\Users\Main\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
  File "C:\Users\Main\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\Main\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
  File "C:\Users\Main\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 74
  (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Windows NT 10.0.17134 x86_64)

正如你所看到的,它说我需要版本74 chrome,但我已经拥有了它!

python google-chrome selenium-webdriver webdriver selenium-chromedriver
1个回答
0
投票

此错误消息...

selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 74
  (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Windows NT 10.0.17134 x86_64)

...暗示ChromeDriver预计Chrome浏览器版本为74。

您的主要问题是您使用的二进制文件版本之间的不兼容性如下:

支持Chrome v74

假设您的系统中安装了多个版本的Chrome浏览器,并且chromedriver = 74.0.3729.6访问的默认位置安装的Chrome浏览器版本不是Chrome浏览器v74.0。因此,您会看到错误。


最快的解决方案是将默认位置安装的Chrome版本升级到Chrome v74级别。


替代

或者,如果您要使用安装在非标准位置的Chrome浏览器二进制文件,则可以使用ChromeOptions()binary_location属性的实例指向非标准Chrome浏览器位置,如下所示:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.binary_location = "C:\\Program Files\\Chrome\\chrome64_55.0.2883.75\\chrome.exe"
driver = webdriver.Chrome(chrome_options = options, executable_path=r'C:\path\to\chromedriver.exe')
driver.get('http://google.com/')
print("Chrome Browser Invoked")
driver.quit()

你可以在Cannot find Chrome binary with Selenium in Python for older versions of Google Chrome找到详细的讨论

© www.soinside.com 2019 - 2024. All rights reserved.