WebDriverException:消息:未知错误:Chrome 无法启动:在 Amazon Linux 上通过 Selenium Python 使用 ChromeDriver Chrome 发生崩溃错误

Bre*_*old 7 python linux selenium google-chrome selenium-chromedriver

只是为了表明我已经尽了应有的努力,对于以下问题,我已经尝试了建议的答案,或者至少仔细阅读并尝试理解它们:

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

从 chrome 位置 C:\..\Chrome\Application\chrome.exe 启动的进程不再运行,因此 ChromeDriver 假设 Chrome 已崩溃

通过docker使用Selenium python库,Chrome报错无法启动:异常退出

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

如何修复 Linux 中的“usr/bin/google-chrome 不再运行,因此 ChromeDriver 假设 Chrome 已崩溃”错误? - 对于这个,我用“/etc/alternatives/google-chrome”替换了“/usr/bin/google-chrome”,但仍然不起作用。

从 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: 消息: chrome 无法访问

硒铬无法启动

WebDriverException:消息:未知错误:Chrome 无法启动:在 VPS 上通过 Python 使用 ChromeDriver Chrome 和 Selenium 异常退出

使用 Chrome 浏览器在 Selenium Grid 中执行测试脚本时出现“Chrome 无法访问”错误

Selenium webdriver 错误 Chrome 无法启动

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

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

当我在 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.)
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

#!/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()
Run Code Online (Sandbox Code Playgroud)

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

附加信息,如果我只是从命令行运行 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
Run Code Online (Sandbox Code Playgroud)

任何帮助是极大的赞赏。

Deb*_*anB 3

这个错误信息...

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

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

\n\n
\n\n

根据Selenium 中的讨论:WebDriverException:Chrome 无法启动:崩溃,因为 google-chrome 不再运行,因此 ChromeDriver 假设 Chrome 已崩溃, 的预期默认位置是:

\n\n
/usr/bin/google-chrome\n
Run Code Online (Sandbox Code Playgroud)\n\n

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

\n\n

因此,理想情况下,以下最小代码块应该有效:

\n\n
from selenium import webdriver\nfrom selenium.webdriver.chrome.options import Options\n\noptions = Options()\noptions.binary_location = \'/usr/bin/google-chrome\'\ndriver = webdriver.Chrome(options=options, executable_path=\'/usr/local/bin/chromedriver\')\ndriver.get(\'http://www.google.com/\')\n
Run Code Online (Sandbox Code Playgroud)\n\n

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

\n\n
[ec2-user@ip-xxx-xx-xx-xxx bin]$ pwd\n/usr/bin\n[ec2-user@ip-xxx-xx-x-xxx bin]$ google-chrome\nSegmentation fault\n
Run Code Online (Sandbox Code Playgroud)\n\n
\n\n

分段故障

\n\n

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

\n\n

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

\n\n
\n\n

原因及解决办法

\n\n

可能的原因和解决方案是:

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


归档时间:

查看次数:

18415 次

最近记录:

4 年,6 月 前