Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Watir Webdriver - Changing proxy on google chrome

I'm trying to access web from watir webdriver through proxy. Can be HTTP or SOCKS

Here is my code so far. I found sample (last 3 lines), but it gives me error:

irb

require "watir-webdriver"
browser = Watir::Browser.new :chrome

switches = '--proxy-server=88.12.44.205:3128'
browser = Watir::Browser.new :chrome, :switches => switches
browser.goto "http://ipaddresslocation.org"

Started ChromeDriver port=53928 version=18.0.1022.0 log=C:\Users\Raimis\chromedriver.log ArgumentError: :args must be an Array of Strings from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.20.0/lib/s elenium/webdriver/chrome/bridge.rb:71:in create_capabilities' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.20.0/lib/s elenium/webdriver/chrome/bridge.rb:20:ininitialize' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.20.0/lib/s elenium/webdriver/common/driver.rb:37:in new' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.20.0/lib/s elenium/webdriver/common/driver.rb:37:infor' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.20.0/lib/s elenium/webdriver.rb:61:in for' from C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-webdriver-0.5.3/lib/watir -webdriver/browser.rb:35:ininitialize' from (irb):6:in new' from (irb):6 from C:/Ruby193/bin/irb:12:in'

this line gives me error

browser = Watir::Browser.new :chrome, :switches => switches

Any tips on how solve this error?

Edit:

here is the final code which worked for me:

irb
require "watir-webdriver"
browser = Watir::Browser.new :chrome, :switches => ['--proxy-server=88.12.44.205:3128']
browser.goto "http://ipaddresslocation.org"
like image 757
user1237898 Avatar asked Jan 18 '23 08:01

user1237898


1 Answers

The problem is that the 'switches' value needs to be an 'array of strings' rather than just a string.

The following should work:

browser = Watir::Browser.new :chrome, :switches => ['--proxy-server=88.12.44.205:3128']

Or if you have a lot of options to set, then you might do:

switches = Array.new
switches << '--proxy-server=88.12.44.205:3128'
#Add other switches values to the array
browser = Watir::Browser.new :chrome, :switches => switches
like image 118
Justin Ko Avatar answered Jan 21 '23 07:01

Justin Ko