我似乎无法忽略使用带有Watir 6.2.0的Firefox驱动程序的任何证书警告。这是意外行为,还是我没有正确使用API?
示例代码:
require 'watir'
profile = Selenium::WebDriver::Firefox::Profile.new
profile.assume_untrusted_certificate_issuer = false
browser = Watir::Browser.new(:firefox, :profile => profile)
browser.goto 'https://self-signed.badssl.com/
意外结果:
/Users/bshannon/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/response.rb:69:in `assert_ok': Selenium::WebDriver::Error::UnknownError
from /Users/bshannon/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/response.rb:32:in `initialize'
from /Users/bshannon/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/http/common.rb:83:in `new'
from /Users/bshannon/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/http/common.rb:83:in `create_response'
from /Users/bshannon/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/http/default.rb:107:in `request'
from /Users/bshannon/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/http/common.rb:61:in `call'
from /Users/bshannon/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/w3c_bridge.rb:620:in `execute'
from /Users/bshannon/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/remote/w3c_bridge.rb:126:in `get'
from /Users/bshannon/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.3.0/lib/selenium/webdriver/common/navigation.rb:32:in `to'
from /Users/bshannon/.rvm/gems/ruby-2.4.0/gems/watir-6.2.0/lib/watir/browser.rb:78:in `goto'
from /Users/bshannon/Desktop/test.rb:8:in `<main>'
环境:
Watir 6.2.0
Selenium Webdriver 3.3.0
Geckodriver 0.15
Firefox 52.0
Mac OSX
答案 0 :(得分:5)
您可以通过desired capabilities执行此操作。 https://github.com/SeleniumHQ/selenium/wiki/Ruby-Bindings#ssl-certificates还有其他文档。
require 'watir'
capabilities = Selenium::WebDriver::Remote::Capabilities.firefox(accept_insecure_certs: true)
browser = Watir::Browser.new(:firefox, :desired_capabilities => capabilities)
browser.goto 'https://self-signed.badssl.com/'
puts browser.url #=> https://self-signed.badssl.com/
browser.close
答案 1 :(得分:1)
试试这个:
profile.accept_untrusted_certificates = true
profile.assume_untrusted_certificate_issuer = true