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


目录
相关文章
|
2月前
|
Linux Go Python
Python Tricks :The Power Of Decorators
Python Tricks :The Power Of Decorators
18 1
|
2月前
|
Go C# Python
Python Tricks:Python‘s Functions Are First-Class
Python Tricks:Python‘s Functions Are First-Class
33 3
|
2月前
|
Python
Python Tricks : How to Write Debuggable Decorators
Python Tricks : How to Write Debuggable Decorators
15 1
|
3月前
|
JavaScript 前端开发 测试技术
Selenium2Library实现基于GUI的测试
Selenium2Library实现基于GUI的测试
42 0
|
4月前
|
机器学习/深度学习 Linux TensorFlow
【Tensorflow 2】解决tensorflow.python.framework.errors_impl.UnknownError: [_Derived_] Fail to find the...
本文解决了在使用TensorFlow 2.0和Keras API时,尝试使用双向LSTM (tf.keras.layers.Bidirectional) 出现的未知错误问题,并提供了三种解决该问题的方法。
71 3
tensorflow.python.framework.errors_impl.InvalidArgumentError
tensorflow.python.framework.errors_impl.InvalidArgumentError:logits and labels must be broadcastable: logits_size=[8,4] labels_size=[8,2]训练模型时报错,tensorflow.python.framework.errors_impl.InvalidArgu...
125 1
|
中间件 调度 Python
Python Scrapy框架之 Downloader Middleware的使用
Python Scrapy框架之 Downloader Middleware的使用
|
机器学习/深度学习 人工智能 JavaScript
python小知识-Gradio:快速构建你的webApp
Gradio定位是快速构建一个针对人工智能的python的webApp库,在Hugging Face等提供各种模型推理展示的平台广告使用,阿里的魔塔展示也是基于此。
14488 0
python小知识-Gradio:快速构建你的webApp
|
自然语言处理 测试技术 Python
基于UIAutomation+Python+Unittest+Beautifulreport的WindowsGUI自动化测试框架common目录解析
基于UIAutomation+Python+Unittest+Beautifulreport的WindowsGUI自动化测试框架common目录解析
483 0
基于UIAutomation+Python+Unittest+Beautifulreport的WindowsGUI自动化测试框架common目录解析
|
存储 API
selenium源码通读·11 |webdriver/common/touch_actions.py-TouchActions类分析
selenium源码通读·11 |webdriver/common/touch_actions.py-TouchActions类分析
99 0
selenium源码通读·11 |webdriver/common/touch_actions.py-TouchActions类分析