Web Elements

Edit on GitHub

Watir automatically generates classes and methods for all HTML5.1 and SVG2 supported elements and their associated attributes. These classes are encapsulated to give easier access to their specific attributes, making it easier to locate them, and providing custom features unique to them.

Here are some basic examples for interacting with elements:

Text Fields

require 'watir'
b = Watir::Browser.start 'bit.ly/watir-webdriver-demo'
t = b.text_field id: 'entry_1000000'
t.exists?
t.set 'your name'
t.value

Select Lists – Combos

require 'watir'
b = Watir::Browser.start 'bit.ly/watir-webdriver-demo'
s = b.select_list id: 'entry_1000001'
s.select 'Ruby'
s.selected_options

Radios

require 'watir'
b = Watir::Browser.start 'bit.ly/watir-webdriver-demo'
r = b.radio value: 'A gem'
r.exists?
r.set
r.set?

Checkboxes

require 'watir'
b = Watir::Browser.start 'bit.ly/watir-webdriver-demo'
c = b.checkbox value: '1.9.2'
c.exists?
c.set
c.set?

Buttons

require 'watir'
b = Watir::Browser.start 'bit.ly/watir-webdriver-demo'
btn = b.button value: 'Submit'
btn.exists?
btn.click
require 'watir'
b = Watir::Browser.start 'bit.ly/watir-webdriver-demo'
l = b.link text: 'Google Forms'
l.exists?
l.click

Divs & Spans

require 'watir'
b = Watir::Browser.start 'bit.ly/watir-webdriver-demo'
d = b.div class: 'ss-form-desc ss-no-ignore-whitespace'
d.exists?
d.text
s = b.span class: 'powered-by-text'
s.exists?
s.text

WYSIWYG Editors

See: WYSIWYG Editors page