st_site puts " Step 2: enter 'watir' in the search text field." ie.text_field(:name, "q").set "watir" # "q" is the name of the search field puts " Step 3: click the 'Google Search' button." ie.button(:type, "submit").click # "submit" is the type of the Search button puts " Expected Result:" puts " A Google page with results should be shown. '#{content} ' should be high on the list." puts " Actual Result:" if ie.text.include? "#{content}" puts " Test Passed. Found the test string: '#{content} '. Actual Results match Expected Results." else puts " Test Failed! Could not find: '#{content} '." end puts "End of test: Google search." # 使用Watir工具,需要在脚本中加上 require 'watir' # 创建一个IE的实例 ie = Watir::IE.new # 或者在创建的同时直接转到页面 ie = Watir::IE.start('text/') # Watir使用start方法同时创建一个浏览器实例并转到一个页面。 # IE浏览速度 ie.speed = :fast ie.speed = :slow # 页面导航 ie.goto('text/') # 注: ie.goto还可以运行javascript的代码如: ie.goto("javascript: ie.document.write("Hello World");") # 取得当前网页的网址 ie.url # 点击超链接 ie.link(:text , "Pickaxe").click ie.link(:href, /http:\/\/pragmaticprogrammer\/).click ie.link(:name => 'foo', :index => 1).click # 超链接的uri ie.link(:text , "Pickaxe").href ie.link(:index, 1).href ie.link(:text => "reply", :index => 2).href # 超链接的文本 ie.link(:href , /http:\/\/pragmaticprogrammer\/).text =begin 对应的HTML代码为: Pick axe =end # img标签 ie.image(:name, 'image').src ie.image(:index, 2).src =begin 对应的HTML代码为: