6
# Match an `a` link element.
8
# @param [String] locator
9
# Text, id, title, or image alt attribute of the link
12
locator = locator.to_s
13
link = descendant(:a)[attr(:href)]
14
link[attr(:id).equals(locator) | string.n.contains(locator) | attr(:title).contains(locator) | descendant(:img)[attr(:alt).contains(locator)]]
17
# Match a `submit`, `image`, or `button` element.
19
# @param [String] locator
20
# Value, title, id, or image alt attribute of the button
23
locator = locator.to_s
24
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)]
25
button += descendant(:button)[~attr(:disabled)][attr(:id).equals(locator) | attr(:value).contains(locator) | string.n.contains(locator) | attr(:title).contains(locator)]
26
button += descendant(:input)[~attr(:disabled)][attr(:type).equals('image')][attr(:alt).contains(locator)]
30
# Match anything returned by either {#link} or {#button}.
32
# @param [String] locator
33
# Text, id, title, or image alt attribute of the link or button
35
def link_or_button(locator)
36
link(locator) + button(locator)
40
# Match any `fieldset` element.
42
# @param [String] locator
43
# Legend or id of the fieldset
46
locator = locator.to_s
47
descendant(:fieldset)[attr(:id).equals(locator) | child(:legend)[string.n.contains(locator)]]
51
# Match any `input`, `textarea`, or `select` element that doesn't have a
52
# type of `submit`, `image`, or `hidden`.
54
# @param [String] locator
55
# Label, id, or name of field to match
58
locator = locator.to_s
59
xpath = descendant(:input, :textarea, :select)[~attr(:type).one_of('submit', 'image', 'hidden')]
60
xpath = locate_field(xpath, locator)
65
# Match any `input` or `textarea` element that can be filled with text.
66
# This excludes any inputs with a type of `submit`, `image`, `radio`,
67
# `checkbox`, `hidden`, or `file`.
69
# @param [String] locator
70
# Label, id, or name of field to match
72
def fillable_field(locator)
73
locator = locator.to_s
74
xpath = descendant(:input, :textarea)[~attr(:type).one_of('submit', 'image', 'radio', 'checkbox', 'hidden', 'file')]
75
xpath = locate_field(xpath, locator)
80
# Match any `select` element.
82
# @param [String] locator
83
# Label, id, or name of the field to match
86
locator = locator.to_s
87
locate_field(descendant(:select), locator)
91
# Match any `input` element of type `checkbox`.
93
# @param [String] locator
94
# Label, id, or name of the checkbox to match
97
locator = locator.to_s
98
locate_field(descendant(:input)[attr(:type).equals('checkbox')], locator)
102
# Match any `input` element of type `radio`.
104
# @param [String] locator
105
# Label, id, or name of the radio button to match
107
def radio_button(locator)
108
locator = locator.to_s
109
locate_field(descendant(:input)[attr(:type).equals('radio')], locator)
113
# Match any `input` element of type `file`.
115
# @param [String] locator
116
# Label, id, or name of the file field to match
118
def file_field(locator)
119
locator = locator.to_s
120
locate_field(descendant(:input)[attr(:type).equals('file')], locator)
124
# Match an `optgroup` element.
126
# @param [String] name
127
# Label for the option group
129
def optgroup(locator)
130
locator = locator.to_s
131
descendant(:optgroup)[attr(:label).contains(locator)]
135
# Match an `option` element.
137
# @param [String] name
138
# Visible text of the option
141
locator = locator.to_s
142
descendant(:option)[string.n.equals(locator)]
146
# Match any `table` element.
148
# @param [String] locator
149
# Caption or id of the table to match
150
# @option options [Array] :rows
151
# Content of each cell in each row to match
154
locator = locator.to_s
155
descendant(:table)[attr(:id).equals(locator) | descendant(:caption).contains(locator)]
158
# Match any 'dd' element.
160
# @param [String] locator
161
# Id of the 'dd' element or text from preciding 'dt' element content
162
def definition_description(locator)
163
locator = locator.to_s
164
descendant(:dd)[attr(:id).equals(locator) | previous_sibling(:dt)[string.n.equals(locator)] ]
169
def locate_field(xpath, locator)
170
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))]
171
locate_field += descendant(:label)[string.n.contains(locator)].descendant(xpath)
172
locate_field[~attr(:disabled)]