会话未创建异常:消息:会话未创建:此版本的ChromeDriver仅支持Chrome 81版本。

184
我目前对Robot Framework还不熟悉。我正在使用最新版本的Chrome和Chromedriver,即80版本,但是当我尝试运行测试时,在Pycharm中出现“SessionNotCreatedException: Message:session not created: This version of ChromeDriver only supports Chrome version 81”的提示,但目前只有81的beta版本可用。我已经尝试卸载并重新安装,但是仍然没有作用,有人能帮我解决吗?谢谢!以下是截图: 1 2

为什么不使用版本81?它与版本80不兼容。 - AndiCover
仅有测试版可用,且不支持此功能。 - finlandlearner
1
在Selenium(Angular 8.2.x)中运行E2E测试时出现相同问题(驱动程序信息:chromedriver = 81.0.4044.20(f006328e39a9769596eb506c8841c3004b24e747-refs / branch-heads / 4044 @ {# 244}),platform = Windows NT 10.0.18362 x86_64) 在Object.checkLegacyResponse(.. \ node_modules \ selenium-webdriver \ lib \ error.js: 546:15)处 在parseHttpResponse(.. \ node_modules \ selenium-webdriver \ lib \ http.js: 509:13)处 在.. \ node_modules \ selenium-webdriver \ lib \ http.js: 441:30处 在processTicksAndRejections(internal / process / task_queues.js: 94:5)处 [08:54:47] E / launcher-进程以错误代码100退出 - JWallace
2
在我的情况下,我所要做的就是打开我的普通Chrome浏览器,进入菜单“帮助->关于Google Chrome”,然后它开始更新Chrome到最新版本(我有81并更新到83)。重新启动Chrome,当我重新运行chromedriver时,它就可以工作了。 - User
你只需要简单地更新ChromeDriver即可。我在Medium上写了一篇简单的文章来介绍如何更新ChromeDriver。 - ScottyBlades
这个回答解决了你的问题吗?[错误信息:“'chromedriver'可执行文件需要在路径中可用”] (https://dev59.com/HF0a5IYBdhLWcg3w3L8-) - AncientSwordRage
39个回答

2

你的 Chrome Driver 版本需要与你的 Chrome 浏览器 版本匹配。

  1. 通过输入 chrome://version 获取你的 Chrome 浏览器版本。

在此处输入图片描述

  1. 这个网站下载与你的 Chrome 浏览器版本相匹配的 Chrome Driver 版本。

请将以下与编程有关的内容从英语翻译成中文。只返回已翻译的文本:请不要重复回答。它已经被回答了,您能在发帖前阅读吗? - Mickael B.
我在另一页回答了这个问题,想着可能应该在这里也加上,所以没有去看这里的答案,下次会注意的。 - ASAD HAMEED

2
你需要安装webdriver管理器。确保webdriver管理器也已经更新。
如果使用npm:
npm install -g webdriver-manager webdriver-manager update

非常简单且有效的解决方案。谢谢。 - Anh Hoang

2

对我有效的命令是:

pip install chromedriver-binary==your_chrome_version

这将卸载您当前安装的Chrome驱动程序,并安装与您的Chrome版本匹配的Chrome驱动程序。

2

如果您在自动集群上运行程序时遇到此错误,并且每次下载的是Google Chrome的稳定版本,则可以使用以下shell脚本动态下载兼容版本的Chrome驱动程序,即使Chrome的稳定版本已更新。

%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驱动程序,并且它完美地运行而没有任何问题。

希望能以某种方式帮助其他人。


1

有特定于驱动程序的NuGet包,可以将驱动程序二进制文件复制到您的 bin 文件夹中。例如,在我的 .NET Core 项目中,我使用来自此处的最新稳定 NuGet https://www.nuget.org/packages/Selenium.WebDriver.ChromeDriver/
基本上,NuGet 包含 chromedriver.exe,并在每次复制到您的程序集文件夹中(在我的情况下是 \bin\Debug\netcoreapp3.1)。这是我在项目中使用的行:

"<PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="*" />"

你可以使用以下方式添加:

dotnet add package Selenium.WebDriver.ChromeDriver --version *

当我第一次添加此引用时,我看到了有关此特定包的警告,但在关闭并重新打开我的Visual Studio 2019后,它消失了。
星号表示将使用最新(最高数字)稳定的软件包,如 此处 所述。
当然,您可以手动安装最新版本(不使用通配符,而是选择特定版本),然后在每个2个主要Chrome版本上更新NuGet软件包引用,以使其与您的Chrome版本匹配。(87 chromedriver适用于87和88 Chrome,但不适用于89)。 然后,使用以下行来实例化驱动程序:

var driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

这种方法消除了需要指定具体路径到chromedriver.exe的需求,因为它将不得不更新。

Reference:
https://www.automatetheplanet.com/webdriver-net50/


1
如果你在使用Selenium.WebDriver.ChromeDriver by jsakamoto时,在Visual Studio 2019中遇到此错误,请检查packages.config文件中引用的版本。
  <package id="Selenium.WebDriver.ChromeDriver" version="89.0.4389.2300" targetFramework="net45" />

更新你的NuGet包到适当的版本并解决问题。


1

您可以处理此异常

from selenium.common.exceptions import SessionNotCreatedException

添加此功能

def update_chrome():
try:
    print("Updating chrome driver")
    download_chrome = "wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb"
    unpack_chrome = "sudo dpkg -i google-chrome-stable_current_amd64.deb"
    install_chrome = "sudo apt-get -f install"
    
    file_path = os.path.join(os.environ['HOME'], "google-chrome-stable_current_amd64.deb")
    if os.path.isfile(file_path):
        print("{} found\nremoving {}".format(file_path, file_path))
        os.remove(file_path)
    else:
        print("File does not exist {}".format(file_path))
    
    old_chrome_ver = os.popen("/usr/bin/google-chrome --version").read().strip('Google Chrome ').strip().split(".")[0]
    print("Current Chrome version: {}".format(old_chrome_ver))
    
    os.system(command=download_chrome)
    sleep(2)
    os.system(command=unpack_chrome)
    sleep(5)
    os.system(command=install_chrome)
    
    crnt_chrome_ver = os.popen("/usr/bin/google-chrome --version").read().strip('Google Chrome ').strip().split(".")[0]
    print("Current Chrome version: {}".format(crnt_chrome_ver))
    
    if crnt_chrome_ver == old_chrome_ver:
        print("Chrome version is same as before")
    elif crnt_chrome_ver > old_chrome_ver:
        print("Chrome version is updated from {} to {}".format(old_chrome_ver, crnt_chrome_ver))
    return True    

except Exception as e:
    print("Error while updating chrome: {}".format(e))
    return False

然后调用这个函数

try:
    # Your code here
except SessionNotCreatedException as snce:
    print("Session not created: {}".format(snce))
    chrome_update_result = False
    if recurrences == 0:
        chrome_update_result = update_chrome()
    if chrome_update_result:
        recurrences += 1
        print("Chrome updated successfully")
        erisapedia_bot(state, download_dir)
        return True
    else:
        print("Chrome update failed")
        return False

1

我已经在与会话想要运行的相同端口上运行了本地服务器,这导致了错误。关闭该本地服务器解决了我的问题。


1
我最近升级了Chrome,也将我的Mac升级到了Big Sur后出现了这个错误。似乎cask不是brew命令的一部分,需要单独使用它。
brew install --cask chromedriver

1
当你的Chrome正在更新时,会出现这种异常情况。在我的情况下,chromedriver已经更新,但Chrome本身仍然是v81而不是v83。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接