watir学习系列--google搜索示例

require 'watir'                                       #必须包含watir


check_text = "watir测试框架"                   #定义局部变量
ie = Watir::IE.new                                 # 打开一个IE浏览器
ie.goto("http://www.google.cn")             #打开google首页
ie.text_field(:name,"q").set(check_text)   #输入搜索内容
sleep(1)
ie.radio(:index, 3).set                      
sleep(1)
ie.button(:name,"btnG").click                 # 点击按钮“Google搜索”
if ie.contains_text("符合#{check_text}的查询结果")
  puts "搜索成功!"
else
  puts "搜索失败!"
end
sleep(1)
ie.close                                               #关闭IE窗口

posted @ 2008-08-25 09:22  赵献良  阅读(991)  评论(2编辑  收藏  举报