我是watir和Ruby的新手。我写了一个小代码,试图打开一个链接,关闭浏览器,然后再次打开链接。
require 'watir-webdriver'
br = Watir::Browser.new :firefox
br.goto "http://google.co.in/"
br.close
br.goto "http://google.co.in/"
当我尝试执行此操作时,我收到以下错误
/usr/lib/ruby/1.9.1/net/http.rb:763:in `initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)
from /usr/lib/ruby/1.9.1/net/http.rb:763:in `open'
from /usr/lib/ruby/1.9.1/net/http.rb:763:in `block in connect'
from /usr/lib/ruby/1.9.1/timeout.rb:55:in `timeout'
from /usr/lib/ruby/1.9.1/timeout.rb:100:in `timeout'
from /usr/lib/ruby/1.9.1/net/http.rb:763:in `connect'
from /usr/lib/ruby/1.9.1/net/http.rb:756:in `do_start'
from /usr/lib/ruby/1.9.1/net/http.rb:745:in `start'
from /usr/lib/ruby/1.9.1/net/http.rb:1285:in `request'
from /var/lib/gems/1.9.1/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/http/default.rb:107:in `response_for'
from /var/lib/gems/1.9.1/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/http/default.rb:58:in `request'
from /var/lib/gems/1.9.1/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
from /var/lib/gems/1.9.1/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/bridge.rb:657:in `raw_execute'
from /var/lib/gems/1.9.1/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/bridge.rb:635:in `execute'
from /var/lib/gems/1.9.1/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/remote/bridge.rb:133:in `get'
from /var/lib/gems/1.9.1/gems/selenium-webdriver-2.46.2/lib/selenium/webdriver/common/navigation.rb:33:in `to'
from /var/lib/gems/1.9.1/gems/watir-webdriver-0.8.0/lib/watir-webdriver/browser.rb:76:in `goto'
from dummy.rb:8:in `<main>'
请告诉我该怎么做。感谢。
答案 0 :(得分:2)
就像人类一样,Watir无法在封闭的浏览器中访问页面。您必须创建另一个浏览器实例,这将打开另一个浏览器窗口。在新的浏览器窗口中,您可以访问另一个网页。
require 'watir-webdriver'
br = Watir::Browser.new :firefox
br.goto "http://google.co.in/"
br.close
br = Watir::Browser.new :firefox
br.goto "http://google.co.in/"