Watir与webdriver、proxy、Firefox

Watir与webdriver、proxy、Firefox,firefox,proxy,watir,webdriver,Firefox,Proxy,Watir,Webdriver,我可以在IE中使用watir webdriver,但我更喜欢使用Firefox。 问题:我需要一个代理。 通过谷歌搜索,我找到了一些代码片段,但我无法将它们全部放在一起。 这是我到目前为止制作的,请让我知道我错过了什么: require 'watir-webdriver' FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("network.proxy.http", "proxy.myplace.com");

我可以在IE中使用watir webdriver,但我更喜欢使用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();

另外,我不知道如何使用名为“driver”的变量调用底层Selenium WebDriver

我已经使用此技术设置了Firefox 3.6的路径,以便可以同时使用Firefox 4和3.6进行测试:

Selenium::WebDriver::Firefox.path = ENV['FIREWATIRPATH']
browser = Watir::Browser.new :firefox
所以要做你想做的事:

profile = Selenium::WebDriver::Firefox::Profile.new
proxy = Selenium::WebDriver::Proxy.new(:http => "http://proxy.org:8080")
profile.proxy = proxy

# You have to do a little more to use the specific profile
driver = Selenium::WebDriver.for :firefox, :profile => profile
browser = Watir::Browser.new(driver)
查看:有关更多信息,请参阅


代理行有什么问题

你可以试试:


我们的想法是查看您的设置是关于:config的,并在代码中复制它们。

原始问题的基本问题就在错误消息中

webdrivertest.rb:3: syntax error, unexpected tCONSTANT, expecting keyword_do or '{' or '('
ruby解释器在脚本的第三行看到了一个类似于常量的东西,在这个地方它期待着其他东西

我怀疑这是ruby需要变量名的开始,而您需要一个类名。Ruby希望以大写字母开头的变量是常量。这对于定义一个类很好,但是不创建一个类的实例,因为实例不是常量

看起来您正在尝试使用“new”关键字和其他语言进行新的调用,而不是使用.new方法对任何您想要创建新对象的对象(ruby way)进行调用

比较Mike答案中的代码

profile = Selenium::WebDriver::Firefox::Profile.new
第三行你想做什么

FirefoxProfile profile = new FirefoxProfile();

看看他们有多不同?这是他的方法。

看来我们很接近了。这一行中有一个问题:proxy=Selenium::WebDriver::proxy.new(:http=>)错误消息是Integer()的无效值:“//proxy.unv.org:8080”这意味着它将第一个:之后的任何内容解释为端口号。也许我应该以另一种格式输入http?另外,如果我跳过http://部分,并将代理输入为“proxy.myplace.com:8080“脚本运行,但Firefox没有代理设置,因此无法运行。我打赌您可以执行proxy.new(:http=>'proxy.org',:http_port=>'8080')不…proxy没有http_端口作为选项这似乎可以工作。profile=Selenium::WebDriver::Firefox::profile.new profile[“network.proxy.type”]=1 profile[”network.proxy.http“]=“proxy.myplace.com”profile[“network.proxy.http_port”]=8080 Well说。解决这个新问题可能会导致一个稍微不同的路径。
profile = Selenium::WebDriver::Firefox::Profile.new
profile.proxy = Selenium::WebDriver::Proxy.new :http => '12.12.12.12:8888', :ssl => '15.15.15.15:443'
browser = Watir::Browser.new :firefox, :profile => profile
profile = Selenium::WebDriver::Firefox::Profile.new
profile.proxy = Selenium::WebDriver::Proxy.new :http => '12.12.12.12:8888', :ssl => '15.15.15.15:443'
browser = Watir::Browser.new :firefox, :profile => profile