WebDriverException:消息:未知错误:Chrome 无法启动:在 Amazon Linux 上通过 Selenium Python 使用 ChromeDriver Chrome 时发生崩溃错误 [英] WebDriverException: Message: unknown error: Chrome failed to start: crashed error using ChromeDriver Chrome through Selenium Python on Amazon Linux

查看:53
本文介绍了WebDriverException:消息:未知错误:Chrome 无法启动:在 Amazon Linux 上通过 Selenium Python 使用 ChromeDriver Chrome 时发生崩溃错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Just to show that I have done my due diligince, I have already either tried the suggested answers or at least read them over and tried to understand, for the following questions:

Selenium: WebDriverException:Chrome 无法启动:由于 google-chrome 不再运行而崩溃,因此 ChromeDriver 假设 Chrome 已崩溃

进程从chrome开始位置 C:..ChromeApplicationchrome.exe 不再运行,因此 ChromeDriver 假设 Chrome 已崩溃

Selenium python 库通过 docker, Chrome 错误启动失败:异常退出

Chrome 在使用 Selenium 时崩溃(没有发布答案,但我仍然查看了它)

Chrome crashes when using Selenium (No answer posted but I still looked it over)

如何修复usr/bin/google-chrome 不再运行,因此 ChromeDriver 假定 Chrome 已崩溃"Linux 中的错误?- 对于这个,我用/etc/alternatives/google-chrome"替换了/usr/bin/google-chrome",仍然没有用.

How to fix "usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed" error in Linux? - For this one I substituted the '/usr/bin/google-chrome' with '/etc/alternatives/google-chrome', still didn't work.

该从 chrome 位置/usr/bin/google-chrome 开始的进程不再运行,因此 ChromeDriver 假设 Chrome 已为 Selenium 崩溃

selenium.common.exceptions.WebDriverException:消息:未知错误:Chrome 无法启动:在 Python 中使用 ChromeDriver 和 Selenium 崩溃

python linux selenium:chrome 无法访问

未知错误:Chrome 无法启动:崩溃(selenium,无头模式)

python selenium: WebDriverException: Message: chrome not reachable

Selenium chrome 无法启动

WebDriverException:消息:未知错误:Chrome 失败to start: 在 VPS 上通过 Python 使用 ChromeDriver Chrome 和 Selenium 异常退出

获取Chrome not可达"使用 Chrome 浏览器在 Selenium Grid 中执行测试脚本时出错

Selenium webdriver错误Chrome无法启动

org.openqa.selenium.WebDriverException:未知错误:Chrome 无法启动:崩溃(无头 chrome)

Python:Selenium - 消息:未知错误:Chrome 启动失败:异常退出

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

I am getting a common error that I have seen here on Stack Overflow, when running Selenium with Python on my Amazon Linux server I get the following results:

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

I am using Google Chrome version 79.0.3945.130, and the corresponding chromedriver version ChromeDriver 79.0.3945.36 as speicified in https://sites.google.com/a/chromium.org/chromedriver/downloads

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

Additional info, if I just run google-chrome from the command line, I get:

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

非常感谢任何帮助.

推荐答案

这个错误信息...

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 浏览器 会话.

...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session.

根据 中的讨论Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver 假设 Chrome 已经崩溃 on is:

As per the discussion in Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed, the expected default location of google-chrome on linux is:

/usr/bin/google-chrome

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

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

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

So ideally, the following minimal code block should have worked:

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 会话时,会发生分段错误,即崩溃如下:

But it seems, when you try to initiate a Chrome session manually, Segmentation fault occurs i.e. crashes as follows:

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

<小时>

分段错误

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


Segmentation fault

Segmentation fault (shortened as segfault) or access violation is a fault or failure condition raised by hardware with memory protection, notifying an operating system that the software has attempted to access a restricted area of memory. The OS kernel will, in response, usually perform some corrective action, generally passing the fault on to the offending process (your script) by sending the process a signal.

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

In short, it’s a helper mechanism to restrict programs/scripts from corrupting the memory which does not belong to it. See more here.

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

The pottential reasons and solutions are:

  • Chrome 根本没有安装在系统中,所以你必须安装 Chrome
  • Chrome 未安装在默认位置,因此您必须通过 binary_location 属性传递 chrome 可执行文件的正确位置.
  • 到实际 Chrome 二进制文件的符号链接 /usr/bin/google-chrome 已损坏,因此您可能需要创建符号链接.
  • 用户没有所需的访问权限/usr/bin/google-chrome,因此您提供了访问权限.
  • Chrome is not at all installed within the system, so you have to install Chrome
  • Chrome is not installed at the default location, so you have to pass the correct location of chrome executable through binary_location property.
  • The symlink /usr/bin/google-chrome to the actual Chrome binary got corrupted, so you may have to create the symlink.
  • The user doesn't have required access rights /usr/bin/google-chrome, so you have provide the access rights.

这篇关于WebDriverException:消息:未知错误:Chrome 无法启动:在 Amazon Linux 上通过 Selenium Python 使用 ChromeDriver Chrome 时发生崩溃错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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