Skip to content

Examples

Starting a new browser (and going to a site)

require 'watir'
b = Watir::Browser.new
b.goto("http://www.google.com")

Starting a new browser at a site

require 'watir'
b = Watir::Browser.start("http://www.google.com")

Choosing which browser to start

require 'watir'
Watir::Browser.default = "firefox"
b = Watir::Browser.start("http://www.google.com")

Setting a text field

b.text_field(:name, "username").set "watir"

Clicking a button

b.button(:name, "logon").click

Clearing & setting a checkbox

b.checkbox(:name, "enabled").clear
b.checkbox(:name, "enabled").set

Submitting a form

b.form(:action, "submit").submit

Clicking a link

b.link(:href, "http://google.com").click

Checking for text in a page

puts b.text.include? "llama"

Checking the title of a page

puts b.title

There are several examples from the Watir community.

No comments yet

Leave a Reply

Note: You can use basic XHTML in your comments.

Subscribe to this comment feed via RSS