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,如需转载请自行联系原作者。


目录
相关文章
|
人工智能 开发者
【阅读十分钟,百分百成功】——通过大模型实现对客服回答的质量评估
本文章基于业务实践,总结有关客服质检场景的解决方案和处理经验,为相似场景提供可行的借鉴方法。
2271 121
|
网络架构
数字数据网技术
数字数据网技术
|
Web App开发 资源调度 前端开发
Hello ReactJS
前言 React学习前先搭好环境,官网的例子看着比较分散。结合webpack就可以体验完整的es6开发流程了。 源码:https://github.com/Ryan-Miao/hello-react-js/releases/tag/0.1 1. 环境搭建 涉及以下几个技术。
1638 0