Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using headless chrome with watir webdriver

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)
like image 454
rails4sandeep Avatar asked Aug 17 '17 00:08

rails4sandeep


1 Answers

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.

like image 200
Fandratt Muda Avatar answered Sep 28 '22 16:09

Fandratt Muda