Watir examples

Examples
All examples are designed to work on the live Watir demo form: http://bit.ly/watir-example.

Loading RubyGems
If you’re a first time Ruby user, you need to understand how to load Ruby gems such as Watir. You can require it via the -rubygems command line option or by using the RUBYOPT environment variable. You can also require it manually in your script:
require 'rubygems'


For more information see here.

Including Watir gem to drive Internet Explorer on Windows
require 'watir'

Including Watir-WebDriver gem to drive Firefox/Chrome on Windows/Mac/Linux
require 'watir-webdriver'

Starting a new browser & and going to our site
browser = Watir::Browser.new
browser.goto 'http://bit.ly/watir-example'


Setting a text field
browser.text_field(:name => 'entry.0.single').set 'Watir'

Setting a multi-line text box
browser.text_field(:name => 'entry.1.single').set "I come here from Australia. \n The weather is great here."

Setting and clearing a radio button
browser.radio(:value => 'Watir').set
browser.radio(:value => 'Watir').clear


Setting and clearing check boxes
browser.checkbox(:value => 'Ruby').set
browser.checkbox(:value => 'Python').set
browser.checkbox(:value => 'Python').clear


Clicking a button
browser.button(:name => 'logon').click

Clearing, getting and selecting selection list values
browser.select_list(:name => 'entry.6.single').clear
puts browser.select_list(:name => 'entry.6.single').options
browser.select_list(:name => 'entry.6.single').select 'Chrome'


Clicking a button
browser.button(:name => 'submit').click

Checking for text in a page
puts browser.text.include? 'Your response has been recorded.'

Checking the title of a page
puts browser.title == 'Thanks!'


more info: http://watir.com/examples/


 
 

 

本文转自贺满博客园博客,原文链接:http://www.cnblogs.com/puresoul/archive/2012/03/06/2381346.html,如需转载请自行联系原作者。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值