using headless chrome with watir webdriver
Asked Answered
S

2

5

In the watir documentation (http://watir.com/guides/chrome/), it has been mentioned that doing

Watir::Browser.new :chrome, headless: true

will enable us to use headless chrome

This does not seem to work.

I get an error as below

2.4.0 :001 > require 'watir'
 => true 
2.4.0 :002 > Watir::Browser.new :chrome, headless: true
ArgumentError: unknown option: {:headless=>true}
        from /Users/sandeep.kumar/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.5.1/lib/selenium/webdriver/remote/bridge.rb:86:in `initialize'
        from /Users/sandeep.kumar/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.5.1/lib/selenium/webdriver/remote/bridge.rb:53:in `new'
        from /Users/sandeep.kumar/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.5.1/lib/selenium/webdriver/remote/bridge.rb:53:in `handshake'
        from /Users/sandeep.kumar/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.5.1/lib/selenium/webdriver/chrome/driver.rb:57:in `initialize'
        from /Users/sandeep.kumar/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.5.1/lib/selenium/webdriver/common/driver.rb:46:in `new'
        from /Users/sandeep.kumar/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.5.1/lib/selenium/webdriver/common/driver.rb:46:in `for'
        from /Users/sandeep.kumar/.rvm/gems/ruby-2.4.0/gems/selenium-webdriver-3.5.1/lib/selenium/webdriver.rb:86:in `for'
        from /Users/sandeep.kumar/.rvm/gems/ruby-2.4.0/gems/watir-6.3.0/lib/watir/browser.rb:46:in `initialize'
        from (irb):2:in `new'
        from (irb):2
        from /Users/sandeep.kumar/.rvm/rubies/ruby-2.4.0/bin/irb:11:in `<main>'

The version of chrome I have is 59.0.3071.115

chrome driver version i have is

ChromeDriver 2.20.353124 (035346203162d32c80f1dce587c8154a1efa0c3b

Using

selenium-webdriver 3.4.3

watir 6.7.1 (was 6.3.0)
Sparerib answered 17/8, 2017 at 0:40 Comment(1)
According to watir.com/watir-6-6, "direct support for Chrome’s new headless mode" was introduced in watir 6.6. And FWIW, that's a pretty old version of chromedriver that you're running.Sp
S
4

Update your gems and try something like this:

driver = Watir::Browser.new :chrome, :switches => %w[--ignore-certificate-errors --disable-popup-blocking --disable-translate --disable-notifications --start-maximized --disable-gpu --headless]
driver.driver.manage.timeouts.implicit_wait = 100 # seconds

The --disable-gpu and --headless enables headless for chrome.

Give it a try. Thank you.

Shadowy answered 26/9, 2017 at 2:32 Comment(0)
S
3

This issue is resolved. It seems watir version 6.7.1 supports this but not 6.3.0

When I have the latest version of watir gem it is working fine

Sparerib answered 17/8, 2017 at 0:42 Comment(1)
Considering that the feature was added after watir 6.3 this makes perfect sense.Laciniate

© 2022 - 2024 — McMap. All rights reserved.