【问题标题】:WebDriverException: Message: unknown error: Chrome failed to start: crashed error using ChromeDriver Chrome through Selenium Python on Amazon LinuxWebDriverException:消息:未知错误:Chrome 无法启动:在 Amazon Linux 上通过 Selenium Python 使用 ChromeDriver Chrome 时发生崩溃错误
【发布时间】:2020-05-21 17:31:27
【问题描述】:

为了表明我已经尽职尽责,对于以下问题,我已经尝试过建议的答案,或者至少阅读并尝试理解:

Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed

The process started from chrome location C:\..\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed

Selenium python library via docker, Chrome error failed to start: exited abnormally

Chrome crashes when using Selenium(没有回复但我还是看了看)

How to fix "usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed" error in Linux? - 对于这个,我用“/etc/alternatives/google-chrome”替换了“/usr/bin/google-chrome”,仍然没有用。

The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed for Selenium

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed with ChromeDriver and Selenium in Python

python linux selenium: chrome not reachable

unknown error: Chrome failed to start: crashed(selenium ,headless mode)

python selenium: WebDriverException: Message: chrome not reachable

Selenium chrome failed to start

WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally with ChromeDriver Chrome and Selenium through Python on VPS

Getting "Chrome not reachable" error while executing test scripts in Selenium Grid With Chrome browser

Selenium webdriver error Chrome failed to start

org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: crashed (headless chrome)

Python : Selenium - Message: unknown error: Chrome failed to start: exited abnormally

我在 Stack Overflow 上看到了一个常见错误,在我的 Amazon Linux 服务器上使用 Python 运行 Selenium 时,我得到以下结果:

Traceback (most recent call last):
  File "test-selenium-chrome.py", line 15, in <module>
    driver = webdriver.Chrome(options=options, executable_path='/usr/local/bin/chromedriver')  # Optional argument, if not specified will search path.i
  File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
  (chrome not reachable)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

这是我的代码:

#!/usr/bin/python3
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from pyvirtualdisplay import Display

options = Options()
options.binary_location = '/usr/bin/google-chrome'
options.add_argument('--disable-extensions')
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--remote-debugging-port=9515')
options.add_argument('--disable-setuid-sandbox')

display = Display(visible=0, size=(800, 800))
display.start()

driver = webdriver.Chrome(options=options, executable_path='/usr/local/bin/chromedriver')  # Optional argument, if not specified will seearch path.i
driver.maximize_window()
driver.get('http://www.google.com/')
time.sleep(5)  # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5)  # Let the user actually see something!
driver.quit()

我使用的是 Google Chrome 版本 79.0.3945.130,以及 https://sites.google.com/a/chromium.org/chromedriver/downloads 中指定的相应 chromedriver 版本 ChromeDriver 79.0.3945.36

附加信息,如果我只是从命令行运行 google-chrome,我会得到:

[ec2-user@ip-xxx-xx-xx-xxx bin]$ pwd
/usr/bin
[ec2-user@ip-xxx-xx-x-xxx bin]$ google-chrome
Segmentation fault

非常感谢任何帮助。

【问题讨论】:

  • 您是否尝试过使用最新的 chrome 驱动程序版本?
  • 嗨 Muzzamil,是的,我使用 chromedriver 版本 80.0.3987.16 进行了尝试。仍然得到相同的结果。
  • 好的,chrome 驱动程序二进制路径和 chrome 选项的顺序在 webdriver.Chrome() 中是否正确?我认为路径应该是第一位的,然后是选项。
  • 嗨 Muzzami,我只是颠倒了顺序并尝试了 driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver', options=options) 仍然没有工作。跨度>
  • 有人在 github 操作(部署部分)中收到此错误

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


【解决方案1】:

此错误消息...

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
  (chrome not reachable)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

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


根据Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed 中的讨论, 上的预期默认位置是:

/usr/bin/google-chrome

注意:对于 Linux 系统,ChromeDriver 期望 /usr/bin/google-chrome 成为实际 Chrome 二进制文件的符号链接。

因此,理想情况下,以下最小代码块应该可以工作:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.binary_location = '/usr/bin/google-chrome'
driver = webdriver.Chrome(options=options, executable_path='/usr/local/bin/chromedriver')
driver.get('http://www.google.com/')

但似乎,当您尝试手动启动 Chrome 会话时,会发生分段错误,即崩溃如下:

[ec2-user@ip-xxx-xx-xx-xxx bin]$ pwd
/usr/bin
[ec2-user@ip-xxx-xx-x-xxx bin]$ google-chrome
Segmentation fault

分段错误

Segmentation fault(缩写为segfault)或访问冲突是由具有内存保护的硬件引发的故障或故障情况,通知操作系统该软件已尝试访问内存的受限区域。作为响应,操作系统内核通常会执行一些纠正措施,通常通过向进程发送信号将错误传递给有问题的进程(您的脚本)。

简而言之,它是一种辅助机制,用于限制程序/脚本破坏不属于它的内存。查看更多here


原因及解决办法

可能的原因及解决办法有:

  • Chrome 根本没有安装在系统中,所以你必须安装 Chrome
  • Chrome 未安装在默认位置,因此您必须通过 binary_location 属性传递 chrome 可执行文件的正确位置。
  • 指向实际 Chrome 二进制文件的符号链接 /usr/bin/google-chrome 已损坏,因此您可能需要创建符号链接。
  • 用户没有所需的访问权限/usr/bin/google-chrome,因此您提供了访问权限。

【讨论】:

  • 嗨 DebanjanB,我尝试将 /usr/bin/google-chrome 的所有权更改为 ec2-user:apache,但仍然遇到分段错误。
  • 只是为了尽职调查,我已经按照解决方案的建议安装了它,并在代码中正确指定了工作符号链接的路径(options.binary_location = '/usr/bin/google-铬')
  • @BrentHeigold 你能手动启动 Chrome 浏览上下文吗?
  • 好的听起来不错,感谢您至少帮助我缩小故障排除选项。
  • @dragonsfire 你找到解决方案了吗?
【解决方案2】:

我遇到了同样的问题,只需删除 --headless 行就可以了。

【讨论】:

    猜你喜欢
    • 2018-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-22
    • 1970-01-01
    • 2017-06-17
    • 1970-01-01
    • 2022-12-17
    相关资源
    最近更新 更多