【发布时间】:2019-07-12 15:20:09
【问题描述】:
我对 Centos7 还很陌生,正在尝试在以下环境中开发浏览器自动化解决方案:
操作系统:Centos7 红宝石:2.6 瓦提尔 浏览器:谷歌浏览器 72.0.3626.109 驱动:ChromeDriver 2.46.628388
我的脚本:
require 'watir'
# Initialize the browser with the driver path
site="https://google.com"
browser = Watir::Browser.new :chrome
browser.goto site
得到错误:
`assert_ok': unknown error: Chrome failed to start: exited abnormally (Selenium::WebDriver::Error::UnknownError)
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.46.628388 (4a34a70827ac54148e092aafb70504c4ea7ae926),platform=Linux 3.10.0-957.5.1.el7.x86_64 x86_64)
我在网上找到了多个建议修改 chrome 选项的解决方案,例如:
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
但我不知道在哪里设置这些。我能到达的最近的答案是这里提供的答案:How do I pass options to the Selenium Chrome driver using Python?
谁能帮我逐步解决这个问题?
【问题讨论】:
-
chromedriver.chromium.org/capabilities 将为您提供有关 chrome 功能的背景知识。查看watir.com/watir-6-6,了解如何在
watir中使用它们。实例化浏览器时尝试Watir::Browser.new :chrome, :args => [ "--no-sandbox" ]... -
我尝试按照您的解释传递参数。但是,错误仍然相同:/usr/local/rvm/gems/ruby-2.6.0/gems/selenium-webdriver-3.141.0/lib/selenium/webdriver/remote/response.rb:69:in `assert_ok ': 未知错误: Chrome 无法启动: 异常退出 (Selenium::WebDriver::Error::UnknownError) (未知错误: DevToolsActivePort 文件不存在) (进程从 chrome 位置 /usr/bin/google-chrome不再运行,因此 ChromeDriver 假设 Chrome 已崩溃。)
-
嗯...可能想尝试最新的 chrome + chromedriver。或者查看 chromedriver 日志:chromedriver.chromium.org/logging。祝你好运。
标签: ruby selenium-chromedriver centos7 watir