博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Watir examples
阅读量:6122 次
发布时间:2019-06-21

本文共 1650 字,大约阅读时间需要 5 分钟。

Examples

All examples are designed to work on the live Watir demo form: .
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 .
Including Watir gem to drive Internet Explorer on Windows
require 'watir'
Including  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://hcwua.baihongyu.com/

你可能感兴趣的文章
修改GRUB2背景图片
查看>>
Ajax异步
查看>>
好记性不如烂笔杆-android学习笔记<十六> switcher和gallery
查看>>
JAVA GC
查看>>
codeforce 599B Spongebob and Joke
查看>>
3springboot:springboot配置文件(外部配置加载顺序、自动配置原理,@Conditional)
查看>>
9、Dubbo-配置(4)
查看>>
前端第七天
查看>>
BZOJ 2190[SDOI2008]仪仗队
查看>>
图解SSH原理及两种登录方法
查看>>
[转载] 七龙珠第一部——第058话 魔境圣地
查看>>
【总结整理】JQuery基础学习---样式篇
查看>>
查询个人站点的文章、分类和标签查询
查看>>
基础知识:数字、字符串、列表 的类型及内置方法
查看>>
JSP的隐式对象
查看>>
P127、面试题20:顺时针打印矩阵
查看>>
JS图片跟着鼠标跑效果
查看>>
[SCOI2005][BZOJ 1084]最大子矩阵
查看>>
学习笔记之Data Visualization
查看>>
Leetcode 3. Longest Substring Without Repeating Characters
查看>>