Module: XPath::HTML

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

Instance Method Summary collapse

Methods included from DSL::TopLevel

#anywhere, #attr, #axis, #child, #contains, #css, #current, #descendant, #name, #next_sibling, #previous_sibling, #starts_with, #string, #string_length, #substring, #text

Instance Method Details

#button(locator) ⇒ Object

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



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

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

#checkbox(locator) ⇒ Object

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



96
97
98
99
# 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) ⇒ Object

Match any 'dd' element.



162
163
164
165
# 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) ⇒ Object

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



57
58
59
60
61
62
# 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) ⇒ Object

Match any `fieldset` element.



45
46
47
48
# File 'lib/xpath/html.rb', line 45

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

#file_field(locator) ⇒ Object

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



118
119
120
121
# 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) ⇒ 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`.



72
73
74
75
76
77
# 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

Match an `a` link element.



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

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

Match anything returned by either #link or #button.



35
36
37
# File 'lib/xpath/html.rb', line 35

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

#optgroup(locator) ⇒ Object

Match an `optgroup` element.



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

def optgroup(locator)
  locator = locator.to_s
  descendant(:optgroup)[attr(:label).is(locator)]
end

#option(locator) ⇒ Object

Match an `option` element.



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

def option(locator)
  locator = locator.to_s
  descendant(:option)[string.n.is(locator)]
end

#radio_button(locator) ⇒ Object

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



107
108
109
110
# 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) ⇒ Object

Match any `select` element.



85
86
87
88
# File 'lib/xpath/html.rb', line 85

def select(locator)
  locator = locator.to_s
  locate_field(descendant(:select), locator)
end

#table(locator) ⇒ Object

Match any `table` element.



153
154
155
156
# File 'lib/xpath/html.rb', line 153

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