1
votes

I'm trying to test a series of links. Most work just fine, but some take particularly long to load. All I need to do is verify that a window with the proper title appears, which I am able to do just fine. The problem is when I try to close a page that is still loading, I get a timeout error -- the close method can't complete while Watir webdriver is still waiting for the page to load. I've looked around a lot but have been unable to find a fix for this other than messing with the timeout settings to be however long it takes the webpage to load. Is there any way to force the window to close once I've verfied that the title I'm looking for exists on that window? Thanks!

1

1 Answers

1
votes

Admittedly, these aren't watir-webdriver solutions, but you could use nokogiri or mechanize to retrieve the page titles. That way, you wouldn't even need a browser. Some examples:

Nokogiri

require 'nokogiri'   
require 'open-uri'

URLS = ["http://www.example.org/", "http://www.iana.org/domains/reserved"]

URLS.each do |url|
  page = Nokogiri::HTML(open("#{url}"))  
  puts page.css('title')
end

#=> <title>Example Domain</title>
#=> <title>IANA - IANA-managed Reserved Domains</title>

Mechanize

require 'mechanize'

URLS = ["http://www.example.org/", "http://www.iana.org/domains/reserved"]

URLS.each do |url|
  agent = Mechanize.new
  puts agent.get("#{url}").title 
end

# => Example Domain
# => IANA - IANA-managed Reserved Domains