4
votes

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"
3

3 Answers

5
votes

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
2
votes

If you want to use a SOCKS5 proxy, you can use the following switch

--proxy-server=socks5://localhost:PORT
2
votes

As of chromedriver 2 (check $ chromedriver -v) I've managed to pass commandline arguments to chrome/chromium. For instance, to use tor as a proxy:

args = ['--start-maximized', '--proxy-server=socks://127.0.0.1:9050']
browser = Watir::Browser.new :chrome, :args => args

check other possible arguments in any chrome help documentation like

http://peter.sh/experiments/chromium-command-line-switches/