Ubuntu:selenium.common.exceptions:会话未创建:此版本的 ChromeDriver 仅支持 Chrome 版本 79 [英] Ubuntu: selenium.common.exceptions: session not created: This version of ChromeDriver only supports Chrome version 79

查看:32
本文介绍了Ubuntu:selenium.common.exceptions:会话未创建:此版本的 ChromeDriver 仅支持 Chrome 版本 79的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 AWS 上的 EC2 实例 (ubuntu) 上运行的 Python 脚本.它使用硒.它完美地工作了数周,然后突然之间,今天,它停止工作,出现以下错误:

selenium.common.exceptions.SessionNotCreatedException:消息:会话未创建:此版本的 ChromeDriver 仅支持 Chrome 版本 79

这是我在 ubuntu 上运行的 python 脚本:

#install 依赖从硒导入网络驱动程序从 selenium.webdriver.chrome.options 导入选项从 selenium.common.exceptions 导入 ElementNotVisibleException从 selenium.common.exceptions 导入 NoSuchElementException从 selenium.common.exceptions 导入 TimeoutExceptionfrom selenium.webdriver.common.by import By从 selenium.webdriver.support.ui 导入 WebDriverWait从 selenium.webdriver.support 导入 expected_conditions 作为 EC#设置chromedriver选项 = 选项()options.add_argument('--no-sandbox')options.add_argument('--window-size=1420,1080')options.add_argument('--headless')options.add_argument('--disable-dev-shm-usage')options.add_argument('--disable-gpu')options.add_argument("--disable-notifications")驱动程序 = webdriver.Chrome(chrome_options=options)

奇怪的是,chromedriver 和chromium-browser 似乎兼容.

运行 chromedriver -v 我看到版本是:

ChromeDriver 79.0.3945.79 (29f75ce3f42b007bd80361b0dfcfee3a13ff90b8-refs/branch-heads/3945@{#916})

而且,运行 chromium-browser --version 我得到:

Chromium 79.0.3945.79 构建于 Ubuntu 上,运行于 Ubuntu 18.04

运行 chromium-browser -v 我看到:

(chromium-browser:2901): Gtk-WARNING **: 17:28:14.613: 无法打开显示:

我希望回答的两个问题:

  1. 怎么可能工作了几个星期,然后突然之间,chromedriver 和 chrome 决定不相互合作?可能是 chromedriver 或 chrome 更新了而另一个没有更新?除了更新从 crontab 运行脚本的时间之外,我没有做任何更改.

  2. 当我的 chromedriver 和 chrome 浏览器是完全相同的版本时,为什么会发生此错误?让 chromedriver 在 ubuntu 上使用 chrome(无头)是一个非常漫长的过程,如果可能的话,我想设置它并忘记它".寻找离开以更好地了解这个问题,这样我就可以避免它一次又一次地发生.

谢谢.

解决方案

此错误信息...

selenium.common.exceptions.SessionNotCreatedException:消息:会话未创建:此版本的 ChromeDriver 仅支持 Chrome 版本 79

...暗示 ChromeDriver v79 无法启动/生成新的浏览上下文,即 Chrome 浏览器会话,其中浏览器版本不是 v79.x.

<小时>

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

  • 您提到了使用 chromedriver=79.0.3945.79.虽然 ChromeDriver v79.x 的发布版本是 )
  • 或者您可以使用 chromium-browser 覆盖默认的 Chrome 二进制位置,即 /usr/bin/google-chrome二进制位置遵循文档 在非标准位置使用 Chrome 可执行文件,如下所示:

    from selenium import webdriver从 selenium.webdriver.chrome.options 导入选项选项 = 选项()options.binary_location='/path/to/chromium-browser.exe'driver = webdriver.Chrome(executable_path=r'C:UtilityBrowserDriverschromedriver.exe', options=options)driver.get('http://google.com/')

<块引用>

您可以在How to使用 Selenium 运行 Chromium 浏览器?

  • 清理您的项目工作区,通过您的 IDE重建您的项目,仅使用所需的依赖项.
  • 如果您的基本 Web Client 版本太旧,请将其卸载并安装 Web Client 的最新 GA 和发布版本.
  • 进行系统重启.
  • 非root用户身份执行您的@Test.
  • 总是在 tearDown(){} 方法中调用 driver.quit() 来关闭 &优雅地销毁 WebDriverWeb Client 实例.
<小时>

参考

您可以在以下位置找到相关的详细讨论:

I have a python script running on an EC2 instance (ubuntu) on AWS. It uses selenium. It was working perfectly for weeks, and then all of the sudden, today, it stopped working with the following error:

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

Here is my python script, which I'm running on ubuntu:

#install dependencies
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import ElementNotVisibleException
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import TimeoutException

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

#Set up chromedriver
options = Options()
options.add_argument('--no-sandbox')
options.add_argument('--window-size=1420,1080')
options.add_argument('--headless')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--disable-gpu')
options.add_argument("--disable-notifications")

driver = webdriver.Chrome(chrome_options=options)

What is odd is that chromedriver and chromium-browser appear to be compatible.

Upon running chromedriver -v I see the version is:

ChromeDriver 79.0.3945.79 (29f75ce3f42b007bd80361b0dfcfee3a13ff90b8-refs/branch-heads/3945@{#916})

And, running chromium-browser --version I get:

Chromium 79.0.3945.79 Built on Ubuntu , running on Ubuntu 18.04

Upon running chromium-browser -v I see :

(chromium-browser:2901): Gtk-WARNING **: 17:28:14.613: cannot open display: 

Two questions I'm hoping to answer :

  1. How could work for weeks, and then all of the sudden, chromedriver and chrome decide not to cooperate with each other? Could it be that either chromedriver or chrome was updated without the other being updated? I did not change anything, with the exception of updating the time from which the script was run from crontab.

  2. Why is this error happening when my chromedriver and chrome browser are the exact same version? It was an extremely long process to get chromedriver to work with chrome (headless) on ubuntu and I'd like to "set it and forget it" if possible. Looking for away to better understand this problem so I can avoid it happening again and again.

Thanks.

解决方案

This error message...

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

...implies that the ChromeDriver v79 was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session where the browser version was other then v79.x.


Your main issue is the incompatibility between the version of the binaries you are using as follows:

Supports Chrome v79

  • You are using chromium-browser v79.0.3945.79 browser.
  • ChromeDriver supports google-chrome when installed at the default location with respect to the underlying os:

1For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary.


Solution

There are two solutions:

  • Either you upgrade google-chrome installed at the default location to current Chrome Version 79.0 level. (as per ChromeDriver v79.0 release notes)
  • Or you can override the default Chrome binary location i.e. /usr/bin/google-chrome with the chromium-browser binary location following the documentation Using a Chrome executable in a non-standard location as follows:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    
    options = Options()
    options.binary_location='/path/to/chromium-browser.exe'
    driver = webdriver.Chrome(executable_path=r'C:UtilityBrowserDriverschromedriver.exe', options=options)
    driver.get('http://google.com/')
    

You can find a detailed discussion in How to run a Chromium Browser with Selenium?

  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
  • Take a System Reboot.
  • Execute your @Test as non-root user.
  • Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.

Reference

You can find a relevant detailed discussion in:

这篇关于Ubuntu:selenium.common.exceptions:会话未创建:此版本的 ChromeDriver 仅支持 Chrome 版本 79的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆