如何使用Remote WebDriver for Chrome忽略证书?我尝试运行此代码:
#encoding: utf-8
require 'selenium-webdriver'
include Selenium
capabilities = WebDriver::Remote::Capabilities.chrome(:native_events => true)
driver = WebDriver.for(:remote,
:desired_capabilities => capabilities,
:url => "http://192.168.1.44:4444/wd/hub",
:switches => %w[--ignore-certificate-errors]
)
driver.navigate.to "https://trunk.plus1.oemtest.ru/"
puts driver.title
driver.close
收到错误消息:
home/igor/.rvm/gems/ruby-1.9.2-p290@selenium/gems/selenium-webdriver-2.12.0/lib/selenium/webdriver/remote/bridge.rb:51:in `initialize': unknown option: {:switches=>["--ignore-certificate-errors"]} (ArgumentError)
答案 0 :(得分:1)
这应该可以解决问题:
caps = Selenium::WebDriver::Remote::Capabilities.chrome
caps['chrome.switches'] = %w[--ignore-certificate-errors]
driver = Selenium::WebDriver.for(:remote, :desired_capabilities => caps)
答案 1 :(得分:1)
最新的chromedriver不再支持上述方法。根据{{3}},应该使用chromeOptions:
caps = Selenium::WebDriver::Remote::Capabilities.chrome("chromeOptions" => {"args" => [ "--ignore-certificate-errors" ]})
driver = Selenium::WebDriver.for :remote, url: 'http://localhost:4444/wd/hub', desired_capabilities: caps
答案 2 :(得分:0)
现在看来,请求不安全证书的正确方法是在Selenium::WebDriver::Remote::Capabilities
实例上设置accept_insecure_certs = true
。