【问题标题】:How to fix "usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed" error in Linux? [duplicate]如何修复 Linux 中的“usr/bin/google-chrome 不再运行,因此 ChromeDriver 假设 Chrome 已崩溃”错误? [复制]
【发布时间】:2019-09-15 15:17:18
【问题描述】:

我正在尝试设置 jenkins 服务器以在 Amazon Linux 上使用 Selenium-webdriver(3.142.0) 和 ruby​​(2.3.7) 托管我的自动化框架。如果我尝试使用我的脚本调用 chromedriver,它会说,

"Selenium::WebDriver::Error::UnknownError: 未知错误: Chrome 启动失败: 异常退出 (未知错误:DevToolsActivePort 文件不存在) (从 chrome 位置 /usr/bin/google-chrome 开始的进程不再运行,因此 ChromeDriver 假设 Chrome 已崩溃。) (驱动信息:chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Linux 4.14.104-95.84.amzn2.x86_64 x86_64)”。

我已将我的 chromedriver 放在 '/var/lib/jenkins/driver/chromedriver' 下,并在 .bashrc 中设置了相同的 PATH 并为相同的 '/usr/bin/google-chrome 创建了一个符号链接'。以下是我正在使用的机器的详细信息:

    NAME="Amazon Linux"
    VERSION="2"
    ID="amzn"
    ID_LIKE="centos rhel fedora"
    VERSION_ID="2"
    PRETTY_NAME="Amazon Linux 2"
    ANSI_COLOR="0;33"
    CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
    HOME_URL="https://amazonlinux.com/"```

require 'selenium-webdriver'
options = Selenium::WebDriver::Chrome::Options.new
options.add_argument("--disable-dev-shm-usage");
options.add_argument('--no-sandbox')
driver = Selenium::WebDriver.for :chrome, options: options



>Expected result: Browser should be invoked.
>Actual result: 
Exits with the error "The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed."

【问题讨论】:

  • Edit - 问题有两个原因。 1)我没有尝试使用无头选项和 2)Chrome 二进制文件的版本与 chromedriver 的不匹配。解决了这两个问题,之后脚本运行良好。

标签: ruby linux selenium-webdriver amazon-linux


【解决方案1】:

Chrome 未安装在默认位置。 ChromeDriver check for Chrome 安装在 Linux 系统的默认位置 /usr/bin/google-chrome。如果您在非标准位置使用 Chrome,则需要覆盖 Chrome 二进制位置。

caps = Selenium::WebDriver::Remote::Capabilities.chrome("chromeOptions" => {"binary" => "Actual Path"})

【讨论】:

  • 只需导航到 /usr/bin/ 并检查 google-chrome 是否存在。如果没有,那么您需要在安装实际 chrome 的代码中设置 chrome 二进制路径。我只是说 chrome 驱动程序将寻找 /usr/bin/google-chrome 启动 chrome 的路径,除非您没有为二进制添加设置。
  • 我可以看到 google-chrome-stable 安装在 /usr/bin 下,但我的脚本仍然无法调用 chromedriver,它显示上述相同的错误。
猜你喜欢
  • 2019-09-01
  • 2022-01-24
  • 2021-12-19
  • 1970-01-01
相关资源
最近更新 更多