rubyselenium-webdriverwatir

I used this article 'Attach to a manually opened Chrome browser using debuggerAddress'


I referred to the mentioned article by Justin Ko on attaching the Chrome browser. I had successfully used the same approach in the past, and it worked well for me. However, I am currently attempting it again using the following code.

require 'watir'    
browser = Watir::Browser.new(
  :chrome,
  'chromeOptions' => {'debuggerAddress': '127.0.0.1:8181'})    
browser.goto 'www.google.com'    
browser.text_field(name: 'q').set 'Raja'

and it's generating this error message.

C:\Ruby32\bin\ruby.exe C:/A/TestBot/AppData/Example.rb
C:/Ruby32/lib/ruby/gems/3.2.0/gems/watir-7.3.0/lib/watir/capabilities.rb:29:in `to_args': {"chromeOptions"=>{:debuggerAddress=>"127.0.0.1:8181"}} are unrecognized arguments for Browser constructor (ArgumentError)

      raise ArgumentError, "#{@options} are unrecognized arguments for Browser constructor" unless @options.empty?
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        from C:/Ruby32/lib/ruby/gems/3.2.0/gems/watir-7.3.0/lib/watir/browser.rb:46:in `initialize'
        from C:/A/TestBot/AppData/Example.rb:3:in `new'
        from C:/A/TestBot/AppData/Example.rb:3:in `<main>'

I considered the possibility that the method of passing parameters might have changed, leading me to write the following code.

require 'watir'
chrome_options = { 'debuggerAddress': '127.0.0.1:8181' }    
browser = Watir::Browser.new :chrome, options: chrome_options    
browser.goto 'www.google.com'    
browser.text_field(name: 'q').set 'Raja'

but this is also throwing the following error.

C:\Ruby32\bin\ruby.exe C:/A/TestBot/AppData/Example.rb
C:/Ruby32/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.17.0/lib/selenium/webdriver/common/options.rb:118:in `as_json': These options are not w3c compliant: {:debuggerAddress=>"127.0.0.1:8181"} (Selenium::WebDriver::Error::WebDriverError)
        from C:/Ruby32/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.17.0/lib/selenium/webdriver/common/local_driver.rb:42:in `process_options'

Can someone help me to fix this problem?

Ultimately, my goal is to attach the Edge browser using the same approach I use for Chrome. However, I need to first achieve success in attaching the Chrome browser.


Solution

  • The parameter named changed from "debuggerAddress" to "debugger_address":

    browser = Watir::Browser.new(:chrome, options: {debugger_address: '127.0.0.1:8181'})