此版本的ChromeDriver仅支持Chrome 79版-Python

时间:2019-11-24 12:44:44

标签: python selenium google-chrome selenium-webdriver selenium-chromedriver

此错误使我发疯。我的代码是:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import chromedriver_binary
from selenium.webdriver.common.by import By
import time
from influxdb import InfluxDBClient
chrome_options = Options()
chrome_options.add_argument("--headless")
chromedriver_binary = 
"/home/dario/scripts/cron_run/web_app_login_checker/chromedriver/chromedriver"
driver = webdriver.Chrome(chromedriver_binary, options=chrome_options)

如果我这样做:

 ./chromedriver -v
 ChromeDriver 79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch- 
 heads/3945@{#614})

这是正确的版本。

完整回溯是:

    Traceback (most recent call last):
    File "grafana.py", line 12, in <module>
    driver = webdriver.Chrome(chromedriver_binary, options=chrome_options)
    File 
   "/home/dario/scripts/cron_run/web_app_login_checker/lib/python3.6/site- 
    packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
    File 
   "/home/dario/scripts/cron_run/web_app_login_checker/lib/python3.6/site- 
   packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
   self.start_session(capabilities, browser_profile)
   File 
   "/home/dario/scripts/cron_run/web_app_login_checker/lib/python3.6/site- 
   packages/selenium/webdriver/remote/webdriver.py", line 252, in 
   start_session
   response = self.execute(Command.NEW_SESSION, parameters)
   File 
   "/home/dario/scripts/cron_run/web_app_login_checker/lib/python3.6/site- 
   packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
   self.error_handler.check_response(response)
   File 
   "/home/dario/scripts/cron_run/web_app_login_checker/lib/python3.6/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 
   79

Stack Overflow上已经讨论过的主题都没有对我有所帮助。

4 个答案:

答案 0 :(得分:3)

问题是Chrome浏览器版本,而不是ChromeDriver版本。您需要将其更新到版本79,或降级ChromeDriver。您可以找到here个匹配的版本。

答案 1 :(得分:1)

如果您在自动集群上运行东西时遇到此错误,并且每次都下载稳定版本的google chrome,则可以使用以下shell脚本每次甚至动态下载chrome驱动程序的兼容版本,甚至如果chrome的稳定版本已更新。您可以执行类似于此python的操作来使其工作。

%sh
#downloading compatible chrome driver version
#getting the current chrome browser version
**chromeVersion=$(google-chrome --product-version)**
#getting the major version value from the full version
**chromeMajorVersion=${chromeVersion%%.*}**
# setting the base url for getting the release url for the chrome driver
**baseDriverLatestReleaseURL=https://chromedriver.storage.googleapis.com/LATEST_RELEASE_**
#creating the latest release driver url based on the major version of the chrome
**latestDriverReleaseURL=$baseDriverLatestReleaseURL$chromeMajorVersion**
**echo $latestDriverReleaseURL**
#file name of the file that gets downloaded which would contain the full version of the chrome driver to download
**latestDriverVersionFileName="LATEST_RELEASE_"$chromeMajorVersion**
#downloading the file that would contain the full release version compatible with the major release of the chrome browser version
**wget $latestDriverReleaseURL** 
#reading the file to get the version of the chrome driver that we should download
**latestFullDriverVersion=$(cat $latestDriverVersionFileName)**
**echo $latestFullDriverVersion**
#creating the final URL by passing the compatible version of the chrome driver that we should download
**finalURL="https://chromedriver.storage.googleapis.com/"$latestFullDriverVersion"/chromedriver_linux64.zip"**
**echo $finalURL**
**wget $finalURL**

在databricks环境上运行预定作业时,我可以使用上述方法获得chrome浏览器和chrome驱动程序的兼容版本,并且它像没有任何问题的魅力一样工作。

希望它可以以一种或其他方式帮助他人。

答案 2 :(得分:1)

  1. 检查您的Chrome版本 How to check the chrome browser version

    1. 下载相同版本的chrome驱动程序 Check the latest driver here

    2. 在参考文件夹中更新驱动程序。

就我而言,我使用的是Windows 10和python,并已使用最新的chromedriver.exe文件更新(适用于Chrome v83) I've backup old driver and keep the latest driver for the version support for the chrome version

答案 3 :(得分:0)

此错误消息...

selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 79

...表示 ChromeDriver 无法启动/产生新的浏览上下文,即 Chrome浏览器v79.x 会话。 / p>

您的主要问题是所使用的二进制版本之间的不兼容性

  

支持 Chrome 79版

  • 大概您正在使用最新的版本78.0.3904.108(正式版本)

ChromeVersion 78.0.3904.108

因此 ChromeDriver v79.0.3945.36 Chrome浏览器v78.0.3904.108

之间明显不匹配

解决方案

有两种可能的解决方案: