我可以在IE中使用watir-webdriver,但我更喜歡使用Firefox。 問題:我需要一個代理。 通過使用Google搜索,我發現了一些代碼片段,但我無法將它們放在一起。 這是我公司生產到現在,請讓我知道我在想什麼:Watir with webdriver,proxy,Firefox
require 'watir-webdriver'
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.http", "proxy.myplace.com");
profile.setPreference("network.proxy.http_port", 8080);
WebDriver driver = new FirefoxDriver(profile);
browser = Watir::Browser.new :firefox
browser.goto("http://www.google.com/")
我收到此錯誤信息:
I:/watir/webdriver/webdrivertest.rb:3: syntax error, unexpected tCONSTANT, expec
ting keyword_do or '{' or '('
FirefoxProfile profile = new FirefoxProfile();
另外,我不知道如何使用變量稱爲「驅動程序」
看起來我們很接近。 這一行有個問題: proxy = Selenium :: WebDriver :: Proxy.new(:http =>「http://proxy.myplace.org:8080」) 錯誤消息是無效值Integer():「//proxy.unv.org:8080」 這意味着它將解釋第一個之後的任何內容:作爲端口號。也許我應該以另一種格式輸入http? – 2011-03-25 14:27:17
另外,如果我跳過http://部分,並輸入代理爲「proxy.myplace.com:8080」,腳本將運行,但Firefox不會獲得代理設置,因此無法運行 – 2011-03-25 14:34:36
我敢打賭,您可以執行此操作Proxy.new(:http =>'proxy.org',:http_port =>'8080') – 2011-03-25 14:34:56