Skip to content
Samuel Garratt edited this page Oct 14, 2018 · 34 revisions

Elements are the items that appear on the html page. Using page-object you can find and interact with a large number of elements. This page lists the elements, the generated methods, and info on what values you can use to find an element.

Button

You declare a Button using the following method call:

button(:your_name, :id => 'an_id')

Two methods are generated with this call. They are:

your_name             # clicks the Button
your_name_element     # returns the Button element

You can locate a Button by providing one or more of the following values:

  • :alt => Watir and Selenium (input type=image only)
  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :src => Watir and Selenium (input type=image only)
  • :text => Watir and Selenium
  • :value => Watir and Selenium
  • :xpath => Watir and Selenium

Cell (td)

You declare a Cell using the following method call:

cell(:your_name, :id => 'an_id')

Two methods are generated with this call. They are:

your_name             # returns the text within the Cell
your_name_element     # returns the Cell element

You can locate a Cell by provide one or more of the following values:

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :text => Watir and Selenium
  • :xpath => Watir and Selenium

Checkbox

You declare a Checkbox using the following method call:

checkbox(:your_name, :id => 'an_id')

Four methods are generated with this call. They are:

check_your_name          # checks the Checkbox
uncheck_your_name        # unchecks the Checkbox
your_name_checked?       # returns if the Checkbox is checked
your_name_element        # returns the Checkbox element

You can locate a Checkbox by provide one or more of the following values:

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :value => Watir and Selenium
  • :xpath => Watir and Selenium

Div

You declare a Div using the following method call:

div(:your_name, :id => 'an_id')

Two methods are generated with this call. They are:

your_name             # returns the text within the Div
your_name_element     # returns the Div element

You can locate a Div by provide one or more of the following values:

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :text => Watir and Selenium
  • :xpath => Watir and Selenium

FileField

You declare a FileField using the following method call:

file_field(:your_name, :id => 'an_id')

Two methods are generated with this call. They are:

your_name=            # sets the value in the FileField
your_name_element     # returns the FileField element

You can locate a FileField by providing one or more of the following values:

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :title => Watir and Selenium
  • :xpath => Watir and Selenium

Form

You declare a Form using the following method call:

form(:your_name, :id => 'an_id')

One method is generated with this call. It is:

your_name_element     # returns the Form element

You can locate an Form by provide one or more of the following values:

  • :action => Watir and Selenium
  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :xpath => Watir and Selenium

H1, H2, H3, H4, H5, H6

You declare a Heading element using one of the following method calls:

h1(:your_name, :id => 'an_id')
h2(:your_name, :id => 'an_id')
h3(:your_name, :id => 'an_id')
h4(:your_name, :id => 'an_id')
h5(:your_name, :id => 'an_id')
h6(:your_name, :id => 'an_id')

Two methods are generated with this call. They are:

your_name             # returns the text within the heading tag
your_name_element     # returns the Heading element

You can locate a Heading by provide one or more of the following values:

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :text => Watir and Selenium
  • :xpath => Watir and Selenium

HiddenField

You declare a HiddenField using the following method call:

hidden_field(:your_name, :id => 'an_id')

Two methods are generated with this call. They are:

your_name          # returns the value in the HiddenField
your_name_element  # returns the HiddenField element

You can locate a HiddenField by provide one or more of the following values:

  • :class => Watir and Selenium
  • :css => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :text => Watir and Selenium
  • :value => Watir and Selenium
  • :xpath => Watir and Selenium

Image

You declare an Image using the following method call:

image(:your_name, :id => 'an_id')

One method is generated with this call. It is:

your_name_element     # returns the Image element

You can locate an Image by provide one or more of the following values:

  • :alt => Watir and Selenium
  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :src => Watir and Selenium
  • :xpath => Watir and Selenium

Link

You declare a Link using the following method call:

link(:your_name, :id => 'an_id')

Two methods are generated with this call. They are:

your_name          # clicks the Link
your_name_element  # returns the Link element

You can locate a Link by provide one or more of the following values:

  • :class => Watir and Selenium
  • :href => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :link => Watir and Selenium
  • :link_text => Watir and Selenium
  • :visible_text => Watir
  • :name => Watir and Selenium
  • :text => Watir and Selenium
  • :xpath => Watir and Selenium

ListItem

You declare a ListItem using the following method call:

list_item(:your_name, :id => 'an_id')

Two methods are generated with this call. They are:

your_name             # returns the text contained in the ListItem
your_name_element     # returns the ListItem element

You can locate a ListItem by provide one or more of the following values:

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :xpath => Watir and Selenium

OrderedList

You declare an OrderedList using the following method call:

ordered_list(:your_name, :id => 'an_id')

Two methods are generated with this call. They are:

your_name             # returns the text contained in the OrderedList
your_name_element     # returns the OrderedList element

You can locate an OrderedList by provide one or more of the following values:

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :xpath => Watir and Selenium

Paragraph

You declare a Paragraph using the following method call:

paragraph(:your_name, :id => 'an_id')

Two methods are generated with this call. They are:

your_name          # returns the text in the Paragraph
your_name_element  # returns the Paragraph element

You can locate a Paragraph by provide one or more of the following values:

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :xpath => Watir and Selenium

RadioButton

You declare a RadioButton using the following method call:

radio_button(:your_name, :id => 'an_id')

Four methods are generated with this call. They are:

select_your_name          # selects the RadioButton
clear_your_name           # clears the RadioButton
your_name_selected?       # returns if the RadioButton is selected
your_name_element         # returns the RadioButton element

You can locate a RadioButton by provide one or more of the following values:

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :xpath => Watir and Selenium

SelectList (Dropdown)

You declare a SelectList using the following method call:

select_list(:your_name, :id => 'an_id')

Four methods are generated with this call. They are:

your_name          # returns the value* selected in the SelectList
your_name=         # sets the selected value* in the SelectList
your_name_element  # returns the SelectList element
your_name_options  # returns an array of available values to pick from in the SelectList 
  • as of version 0.6.3, these actually use the text of the option, not the value

You can locate a SelectList by provide one or more of the following values:

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :text => Watir only
  • :value => Watir only
  • :xpath => Watir and Selenium

Span

You declare a Span using the following method call:

span(:your_name, :id => 'an_id')

Two methods are generated with this call. They are:

your_name             # returns the text within the Span
your_name_element     # returns the Span element

You can locate a Span by provide one or more of the following values:

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :text => Watir and Selenium
  • :xpath => Watir and Selenium

Table

You declare a Table using the following method call:

table(:your_name, :id => 'an_id')

Two methods are generated with this call. They are:

your_name             # returns the text contained within the Table
your_name_element     # returns the Table element

You can locate a Table by provide one or more of the following values:

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :xpath => Watir and Selenium

A table can be navigated by searching for text in a cell. This is done as an index:

table_element['text to find']

This will find the first row that has a cell that contains that text. From a row, a specific cell can be obtained by using a header name as an index:

table_element['text to find']['header name']

Both rows and cells can be located by a specific numeric index: table_element[0][1]

Table element and row elements are enumerable, allowing for the use of select, collect, find, and many other ways of finding and manipulating the data in a table.


TableCell

You declare a TableCell using the following method call:

cell(:your_name, :id => 'an_id')

Two methods are generated with this call. They are:

your_name          # returns the text in the TableCell
your_name_element  # returns the TableCell element

You can locate a TableCell by provide one or more of the following values:

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :text => Watir and Selenium
  • :xpath => Watir and Selenium

TextArea

You declare a TextArea using the following method call:

text_area(:your_name, :id => 'an_id')

Three methods are generated with this call. They are:

your_name          # returns the value in the TextArea
your_name=         # sets the value in the TextArea
your_name_element  # returns the TextArea element

You can locate a TextArea by provide one or more of the following values:

  • :class => Watir and Selenium
  • :css => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :xpath => Watir and Selenium

TextField

You declare a TextField using the following method call:

text_field(:your_name, :id => 'an_id')

Three methods are generated with this call. They are:

your_name          # returns the value in the TextField
your_name=         # sets the value in the TextField
your_name_element  # returns the TextField element

You can locate a TextField by provide one or more of the following values:

  • :class => Watir and Selenium
  • :css => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :text => Watir only
  • :title => Watir only
  • :value => Watir only
  • :label => Watir only
  • :xpath => Watir and Selenium

UnorderedList

You declare an UnorderedList using the following method call:

unordered_list(:your_name, :id => 'an_id')

Two methods are generated with this call. They are:

your_name             # returns the text contained within the UnorderedList
your_name_element     # returns the UnorderedList element

You can locate an UnorderedList by provide one or more of the following values:

  • :class => Watir and Selenium
  • :id => Watir and Selenium
  • :index => Watir and Selenium
  • :name => Watir and Selenium
  • :xpath => Watir and Selenium