如何使用watir打开浏览器?

时间:2013-08-29 12:33:10

标签: ruby firefox selenium-webdriver watir tor

使用我的ruby代码我想打开Tor Browser而不是Firefox,为此我尝试了这段代码

path='C:\Tor Browser\App\tor.exe'
Selenium::WebDriver::Firefox.path = path
driver = Selenium::WebDriver.for :firefox
ie = Watir::Browser.new :firefox, :driver => driver

我收到了这个错误

c:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/firefox/launcher.rb:79:in `connect_until_stable': unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055) (Selenium::WebDriver::Error::WebDriverError)
from c:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/firefox/launcher.rb:37:in `block in launch'
from c:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/firefox/socket_lock.rb:20:in `locked'
from c:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/firefox/launcher.rb:32:in `launch'
from c:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/firefox/bridge.rb:24:in `initialize'
from c:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/common/driver.rb:31:in `new'
from c:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver/common/driver.rb:31:in `for'
from c:/Ruby193/lib/ruby/gems/1.9.1/gems/selenium-webdriver-2.35.1/lib/selenium/webdriver.rb:67:in `for'
from C:/new_trademap/newTrademapTest.rb:28:in `<main>'

我该怎么办?或者还有其他方法吗?

链接link1 google group link

2 个答案:

答案 0 :(得分:0)

答案:

首先,打开Tor浏览器(它需要已经运行)。然后,在您的代码中,确保只需以:

开头
Selenium::WebDriver::Firefox::Binary.path=/Applications/TorBrowser.app/Contents/MacOS/TorBrowser.app/Contents/MacOS/firefox
browser = Watir::Browser.new :firefox

*在我的情况下:/ home / tor / tor-browser_en-US / start-tor-browser

不需要其他任何东西 - 不要乱搞个人资料

答案 1 :(得分:-1)

您的路径C:\Tor Browser\App\tor.exe不是firefox的路径,它是Tor可执行文件的路径。您可能需要做的是修改您的启动浏览器脚本以运行该tor.exe但不启动Firefox,然后单独初始化Tor的Firefox。

另一种选择是将C:\Tor Browser\App\tor.exe的路径修改为TorBrowser的Firefox二进制文件的路径,而现在TorBrowser将Tor和Firefox捆绑成一个可执行文件。