2012-03-02 79 views
3

我試圖通過代理從watir webdriver訪問web。可以是HTTP或SOCKSWatir Webdriver - 更改谷歌瀏覽器上的代理

這是我的代碼到目前爲止。我發現樣品(最後3行),但它給我的錯誤:

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:in initialize' 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:in for' 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:in initialize' from (irb):6:in new' from (irb):6 from C:/Ruby193/bin/irb:12:in '

此行給我的錯誤

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

關於如何解決此錯誤的任何提示?

編輯:

這裏是爲我工作的最終代碼:

irb 
require "watir-webdriver" 
browser = Watir::Browser.new :chrome, :switches => ['--proxy-server=88.12.44.205:3128'] 
browser.goto "http://ipaddresslocation.org" 

回答

4

的問題是,「開關」的值必須是一個「字符串數組」,而不是隻是一個字符串。

下面應該工作:

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

或者,如果你有很多的選項來設置,那麼你可以做:

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 
+0

謝謝!這有助於 – user1237898 2012-03-02 19:11:07

2

從chromedriver 2(檢查$ chromedriver -v)我設法通過命令行argume nts到鉻/鉻。例如,使用Tor作爲代理:

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

檢查其他可能的參數的任何瀏覽器幫助文檔中像

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