python - session 未创建异常 : Message: session not created from disconnected: unable to connect to renderer using Chromedriver on Linux Centos 7 Server

标签 python linux selenium google-chrome selenium-chromedriver

我正在尝试在带有 selenium 和 python 的 Linux Centos 7 服务器上使用 headless chrome。尝试激活驱动程序时出现以下错误:

Traceback (most recent call last):
  File "send_notif_marktplaats.py", line 128, in <module>
    main()
  File "send_notif_marktplaats.py", line 117, in main
    driver = activate_driver()
  File "send_notif_marktplaats.py", line 42, in activate_driver
    driver = webdriver.Chrome(executable_path="/usr/local/bin/chromedriver", chrome_options=optionsChrome)
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/lib/python2.7/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
from disconnected: unable to connect to renderer
  (Session info: headless chrome=80.0.3987.116)

我的版本:

  • Chrome 驱动程序版本 80.0.3987.106
  • 谷歌浏览器 80.0.3987.116

有人可以帮帮我吗?

最佳答案

这个错误信息...

selenium.common.exceptions.SessionNotCreatedException: Message: session not created
from disconnected: unable to connect to renderer
  (Session info: headless chrome=80.0.3987.116)

...暗示 ChromeDriver v80.0 无法启动/生成新的浏览上下文,即 Chrome 浏览器 session 。


根据讨论 WebDriver 80.0.3987.16 can't open Chrome on Linux @triciac 更新了 ChromeDriver 的实现v80.0 按以下顺序查找 Chrome:

  1. locations->push_back(base::FilePath("/usr/local/sbin"));
  2. locations->push_back(base::FilePath("/usr/local/bin"));
  3. locations->push_back(base::FilePath("/usr/sbin"));
  4. locations->push_back(base::FilePath("/usr/bin"));
  5. locations->push_back(base::FilePath("/sbin"));
  6. locations->push_back(base::FilePath("/bin"));
  7. locations->push_back(base::FilePath("/opt/google/chrome"));//最后尝试使用默认安装位置。

@johnchen,确认 Linux 上的二进制搜索顺序被 r708243 意外更改,旨在更轻松地配置 Chrome 二进制文件的名称,但不小心也更改了搜索顺序。

ChromeDriver 团队已更新 ChromeDriver 以通过此 revision 解决此问题/commit .


解决方案

上述解决方案适用于:


临时解决方案

临时解决方案是使用 binary_location 属性,您可以在 Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed 中找到详细讨论。

关于python - session 未创建异常 : Message: session not created from disconnected: unable to connect to renderer using Chromedriver on Linux Centos 7 Server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60299503/

相关文章:

linux - mv三点目录遍历

java - Selenium IDE 测试 try-catch

java - 没有在 Selenium + Appium 上获取动态 ListView 的所有元素

python - 在 Python,pandas 中,当我将列从六进制转换为十进制时如何忽略 Python 中的无效值?

python - "Transform"Numpy 数组 : Move Dimension

linux - session 断开后如何重新连接到后台 GUI 应用程序?

regex - 重命名文件夹及其子文件夹的文件

python - setup.py、setuptools、cmdclass - 自定义命令不起作用

python - 查找轮廓的边缘强度/大小以查找和排除模糊对象

java - 如何在Appium中列出列表中的所有元素