Python Ubuntu:selenium.common.exceptions:未创建会话:此版本的ChromeDriver仅支持ChromeVersion79
我有一个python脚本在AWS上的EC2实例(ubuntu)上运行。它使用硒。几周来,它一直工作正常,但今天突然,它停止了工作,出现了以下错误:Python Ubuntu:selenium.common.exceptions:未创建会话:此版本的ChromeDriver仅支持ChromeVersion79,python,selenium,google-chrome,ubuntu,selenium-chromedriver,Python,Selenium,Google Chrome,Ubuntu,Selenium Chromedriver,我有一个python脚本在AWS上的EC2实例(ubuntu)上运行。它使用硒。几周来,它一直工作正常,但今天突然,它停止了工作,出现了以下错误: selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 79 这是我在ubuntu上运行的python脚本: #inst
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 79
这是我在ubuntu上运行的python脚本:
#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)
奇怪的是chromedriver和Chrome浏览器似乎是兼容的
运行chromedriver-v
后,我看到的版本是:
ChromeDriver 79.0.3945.79 (29f75ce3f42b007bd80361b0dfcfee3a13ff90b8-refs/branch-heads/3945@{#916})
运行chromium浏览器--version我得到:
Chromium 79.0.3945.79 Built on Ubuntu , running on Ubuntu 18.04
运行chromium browser-v时,我看到:
(chromium-browser:2901): Gtk-WARNING **: 17:28:14.613: cannot open display:
我希望回答两个问题:
谢谢。默认情况下,
webdriver.Chrome
运行/usr/bin/google-Chrome
(如果可用),而不是Chrome-browser
(请参阅)。检查google chrome--version此错误消息
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 79
…意味着ChromeDriver v79无法启动/生成新的浏览上下文,即浏览器版本不是v79.x的Chrome浏览器会话
您的主要问题是所使用的二进制文件版本之间的不兼容,如下所示:
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:\Utility\BrowserDrivers\chromedriver.exe', options=options)
driver.get('http://google.com/')
- 您提到使用chromedriver=79.0.3945.79。尽管ChromeDriver v79.x的发布版本是和,但ChromeDriver=79.0.3945.79的发行说明明确提到以下内容:
- 您正在使用chromium浏览器v79.0.3945.79浏览器
- ChromeDriver安装在底层操作系统的默认位置时,支持
:google chrome
/usr/bin/google chrome
是实际chrome二进制文件的符号链接
解决方案 有两种解决方案:
- 您可以将安装在默认位置的
升级到当前的chrome 79.0版本。(根据)google chrome
- 或者您可以使用
二进制位置覆盖默认的Chrome二进制位置,即Chrome浏览器
,如下所示:/usr/bin/google Chrome
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:\Utility\BrowserDrivers\chromedriver.exe', options=options) driver.get('http://google.com/')
- 通过IDE清理项目工作区,并仅使用所需的依赖项重建项目
- 如果您的基本Web客户端版本太旧,请卸载它并安装最新的GA和Web客户端发布版本
- 重新启动系统
- 以非root用户身份执行
@Test
- 始终在
方法中调用tearDown(){}
,以优雅地关闭和销毁Web驱动程序和Web客户端实例driver.quit()
参考文献 有关详细讨论,请参见:
.exe
部分