我可以在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