Module: XPath::HTML

Extended by:
HTML
Includes:
XPath
Included in:
HTML
Defined in:
lib/xpath/html.rb

Constant Summary

Constant Summary

Constants included from XPath

VERSION

Instance Method Summary collapse

Methods included from XPath

generate

Methods included from DSL::TopLevel

#anywhere, #attr, #axis, #child, #contains, #css, #current, #descendant, #name, #starts_with, #string, #text

Instance Method Details

#button(locator) ⇒ Object

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



21
22
23
24
25
# File 'lib/xpath/html.rb', line 21

def button(locator)
  button = descendant(:input)[attr(:type).one_of('submit', 'reset', 'image', 'button')][attr(:id).equals(locator) | attr(:value).contains(locator) | attr(:title).contains(locator)]
  button += descendant(:button)[attr(:id).equals(locator) | attr(:value).contains(locator) | string.n.contains(locator) | attr(:title).contains(locator)]
  button += descendant(:input)[attr(:type).equals('image')][attr(:alt).contains(locator)]
end

#checkbox(locator) ⇒ Object

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



90
91
92
# File 'lib/xpath/html.rb', line 90

def checkbox(locator)
  locate_field(descendant(:input)[attr(:type).equals('checkbox')], locator)
end

#field(locator) ⇒ Object

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



54
55
56
57
58
# File 'lib/xpath/html.rb', line 54

def field(locator)
  xpath = descendant(:input, :textarea, :select)[~attr(:type).one_of('submit', 'image', 'hidden')]
  xpath = locate_field(xpath, locator)
  xpath
end

#fieldset(locator) ⇒ Object

Match any `fieldset` element.



43
44
45
# File 'lib/xpath/html.rb', line 43

def fieldset(locator)
  descendant(:fieldset)[attr(:id).equals(locator) | child(:legend)[string.n.contains(locator)]]
end

#file_field(locator) ⇒ Object

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



110
111
112
# File 'lib/xpath/html.rb', line 110

def file_field(locator)
  locate_field(descendant(:input)[attr(:type).equals('file')], locator)
end

#fillable_field(locator) ⇒ Object

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`.



68
69
70
71
72
# File 'lib/xpath/html.rb', line 68

def fillable_field(locator)
  xpath = descendant(:input, :textarea)[~attr(:type).one_of('submit', 'image', 'radio', 'checkbox', 'hidden', 'file')]
  xpath = locate_field(xpath, locator)
  xpath
end

Match an `a` link element.



11
12
13
14
# File 'lib/xpath/html.rb', line 11

def link(locator)
  link = descendant(:a)[attr(:href)]
  link[attr(:id).equals(locator) | string.n.contains(locator) | attr(:title).contains(locator) | descendant(:img)[attr(:alt).contains(locator)]]
end

Match anything returned by either #link or #button.



33
34
35
# File 'lib/xpath/html.rb', line 33

def link_or_button(locator)
  link(locator) + button(locator)
end

#optgroup(name) ⇒ Object

Match an `optgroup` element.



120
121
122
# File 'lib/xpath/html.rb', line 120

def optgroup(name)
  descendant(:optgroup)[attr(:label).contains(name)]
end

#option(name) ⇒ Object

Match an `option` element.



130
131
132
# File 'lib/xpath/html.rb', line 130

def option(name)
  descendant(:option)[string.n.equals(name)]
end

#radio_button(locator) ⇒ Object

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



100
101
102
# File 'lib/xpath/html.rb', line 100

def radio_button(locator)
  locate_field(descendant(:input)[attr(:type).equals('radio')], locator)
end

#select(locator) ⇒ Object

Match any `select` element.



80
81
82
# File 'lib/xpath/html.rb', line 80

def select(locator)
  locate_field(descendant(:select), locator)
end

#table(locator) ⇒ Object

Match any `table` element.



142
143
144
# File 'lib/xpath/html.rb', line 142

def table(locator)
  descendant(:table)[attr(:id).equals(locator) | descendant(:caption).contains(locator)]
end