無可否認,這些不是watir-webdriver解決方案,但您可以使用nokogiri或mechanize來檢索頁面標題。這樣,你甚至不需要瀏覽器。一些例子:
引入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>
機械化
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