Included Modules

XPath::HTML

Public Instance Methods

button(locator) click to toggle source

Match a `submit`, `image`, or `button` element.

@param [String] locator

Value, title, id, or image alt attribute of the button
# File lib/xpath/html.rb, line 22
def button(locator)
  locator = locator.to_s
  button = descendant(:input)[~attr(:disabled)][attr(:type).one_of('submit', 'reset', 'image', 'button')][attr(:id).equals(locator) | attr(:value).contains(locator) | attr(:title).contains(locator)]
  button += descendant(:button)[~attr(:disabled)][attr(:id).equals(locator) | attr(:value).contains(locator) | string.n.contains(locator) | attr(:title).contains(locator)]
  button += descendant(:input)[~attr(:disabled)][attr(:type).equals('image')][attr(:alt).contains(locator)]
end
checkbox(locator) click to toggle source

Match any `input` element of type `checkbox`.

@param [String] locator

Label, id, or name of the checkbox to match
# File lib/xpath/html.rb, line 96
def checkbox(locator)
  locator = locator.to_s
  locate_field(descendant(:input)[attr(:type).equals('checkbox')], locator)
end
definition_description(locator) click to toggle source

Match any 'dd' element.

@param [String] locator

Id of the 'dd' element or text from preciding 'dt' element content
# File lib/xpath/html.rb, line 162
def definition_description(locator)
  locator = locator.to_s
  descendant(:dd)[attr(:id).equals(locator) | previous_sibling(:dt)[string.n.equals(locator)] ]
end
field(locator) click to toggle source

Match any `input`, `textarea`, or `select` element that doesn't have a type of `submit`, `image`, or `hidden`.

@param [String] locator

Label, id, or name of field to match
# File lib/xpath/html.rb, line 57
def field(locator)
  locator = locator.to_s
  xpath = descendant(:input, :textarea, :select)[~attr(:type).one_of('submit', 'image', 'hidden')]
  xpath = locate_field(xpath, locator)
  xpath
end
fieldset(locator) click to toggle source

Match any `fieldset` element.

@param [String] locator

Legend or id of the fieldset
# File lib/xpath/html.rb, line 45
def fieldset(locator)
  locator = locator.to_s
  descendant(:fieldset)[attr(:id).equals(locator) | child(:legend)[string.n.contains(locator)]]
end
file_field(locator) click to toggle source

Match any `input` element of type `file`.

@param [String] locator

Label, id, or name of the file field to match
# File lib/xpath/html.rb, line 118
def file_field(locator)
  locator = locator.to_s
  locate_field(descendant(:input)[attr(:type).equals('file')], locator)
end
fillable_field(locator) click to toggle source

Match any `input` or `textarea` element that can be filled with text. This excludes any inputs with a type of `submit`, `image`, `radio`, `checkbox`, `hidden`, or `file`.

@param [String] locator

Label, id, or name of field to match
# File lib/xpath/html.rb, line 72
def fillable_field(locator)
  locator = locator.to_s
  xpath = descendant(:input, :textarea)[~attr(:type).one_of('submit', 'image', 'radio', 'checkbox', 'hidden', 'file')]
  xpath = locate_field(xpath, locator)
  xpath
end
optgroup(locator) click to toggle source

Match an `optgroup` element.

@param [String] name

Label for the option group
# File lib/xpath/html.rb, line 129
def optgroup(locator)
  locator = locator.to_s
  descendant(:optgroup)[attr(:label).contains(locator)]
end
option(locator) click to toggle source

Match an `option` element.

@param [String] name

Visible text of the option
# File lib/xpath/html.rb, line 140
def option(locator)
  locator = locator.to_s
  descendant(:option)[string.n.equals(locator)]
end
radio_button(locator) click to toggle source

Match any `input` element of type `radio`.

@param [String] locator

Label, id, or name of the radio button to match
# File lib/xpath/html.rb, line 107
def radio_button(locator)
  locator = locator.to_s
  locate_field(descendant(:input)[attr(:type).equals('radio')], locator)
end
select(locator) click to toggle source

Match any `select` element.

@param [String] locator

Label, id, or name of the field to match
# File lib/xpath/html.rb, line 85
def select(locator)
  locator = locator.to_s
  locate_field(descendant(:select), locator)
end
table(locator) click to toggle source

Match any `table` element.

@param [String] locator

Caption or id of the table to match

@option options [Array] :rows

Content of each cell in each row to match
# File lib/xpath/html.rb, line 153
def table(locator)
  locator = locator.to_s
  descendant(:table)[attr(:id).equals(locator) | descendant(:caption).contains(locator)]
end

Protected Instance Methods

locate_field(xpath, locator) click to toggle source
# File lib/xpath/html.rb, line 169
def locate_field(xpath, locator)
  locate_field = xpath[attr(:id).equals(locator) | attr(:name).equals(locator) | attr(:placeholder).equals(locator) | attr(:id).equals(anywhere(:label)[string.n.contains(locator)].attr(:for))]
  locate_field += descendant(:label)[string.n.contains(locator)].descendant(xpath)
  locate_field[~attr(:disabled)]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.