Watir登陆谷歌搜索关键字

#encoding: UTF-8    #添加这一行才可以处理中文
require 'rubygems'  #gem install xxx --no-ri --no-rdoc
require 'timeout'
require 'watir-webdriver'

begin
 Timeout::timeout(10)  do |timeout_length|  #在国内,google经常被墙导致连接超时
  b.goto 'http://www.google.com.hk/webhp?hl=zh-CN&sourceid=cnhp'
 end
rescue Timeout::Error => e
   puts "page is not completed loaded, program will go on procesing ."
end
b.text_field(:name, 'q').focus
b.text_field(:name, 'q').set('flyuphigh')
b.input(:name, 'btnK').click
puts "当前的网址是:" + b.url
sleep(20)
b.close

Comments !