Search code examples
rubyseleniumselenium-webdriverwatirgeckodriver

Unable to bypass insecure certificate warning with Firefox using Watir


I don't seem to be able to ignore any certificate warnings using the Firefox driver with Watir 6.2.0. Is this unexpected behavior, or am I just not using the API properly?

Example code:

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/

Unexpected result:

/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>'

enter image description here

Environment:

Watir 6.2.0
Selenium Webdriver 3.3.0
Geckodriver 0.15
Firefox 52.0
Mac OSX

Solution

  • You can do this via desired capabilities. There's additional documentation at 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