在Ruby Selenium中运行无头Chrome失败

时间:2018-03-04 15:58:07

标签: ruby selenium selenium-webdriver selenium-chromedriver headless

我已经有红宝石和硒一段时间了。试图实施无头而且失败了。甚至来自网络的简单例子。在几台计算机上使用Windows 10,包括全新的加载适用资源的计算机。 这是测试代码。

require 'selenium-webdriver'
options = Selenium::WebDriver::Chrome::Options.new(args: ['headless'])
puts "I'm here"
driver = Selenium::WebDriver.for(:chrome, options: options)
puts "Now I'm here"
driver.get('http://stackoverflow.com/')
puts driver.title
driver.quit

这是我得到的结果。我的应用程序运行正常,不会无头。

I'm here
[0304/084324.450:ERROR:instance.cc(49)] Unable to locate service manifest for metrics
[0304/084324.450:ERROR:service_manager.cc(890)] Failed to resolve service name: metrics

DevTools listening on ws://127.0.0.1:12145/devtools/browser/626c0a52-00ab-4985-9e1e-d38dfb5161f8
[0304/084324.512:ERROR:instance.cc(49)] Unable to locate service manifest for metrics
[0304/084324.512:ERROR:service_manager.cc(890)] Failed to resolve service name: metrics
[0304/084324.590:ERROR:browser_gpu_channel_host_factory.cc(121)] Failed to launch GPU process.
[0304/084324.590:ERROR:gpu_process_transport_factory.cc(1009)] Lost UI shared context.
[0304/084324.807:ERROR:instance.cc(49)] Unable to locate service manifest for metrics
[0304/084324.807:ERROR:service_manager.cc(890)] Failed to resolve service name: metrics
Now I'm here
[0304/084327.694:INFO:CONSOLE(0)] "The SSL certificate used to load resources from https://js-sec.indexww.com will be distrusted in the future. Once distrusted, users will be prevented from loading these resources. See https://g.co/chrome/symantecpkicerts for more information.", source: https://stackoverflow.com/ (0)
Stack Overflow - Where Developers Learn, Share, & Build Careers

由于

2 个答案:

答案 0 :(得分:0)

当您尝试通过 ChromeDriver 在无头模式下执行@Tests时,您必须按如下方式传递参数:

options = Selenium::WebDriver::Chrome::Options.new(args: ['--headless'])

当您在无头模式下执行@Tests时,在 Windows 10 上,您还必须传递以下参数:

  • 开始最大化
  • - 禁用-GPU
  • - 无沙箱
  

参考Getting Started with Headless Chrome

答案 1 :(得分:-3)

尝试使用这些选项,为我工作

' - 无头'

' - 禁用-web的安全'

' - 隐身'

' - 无沙箱'

' - 禁用-GPU'

' - 窗口尺寸= 1920,1080'