Module: Webdrone::XPath

Extended by:
XPath
Includes:
XPath::DSL
Included in:
XPath
Defined in:
lib/webdrone/xpath.rb

Overview

Code from teamcapybara/xpath Copyright © 2016 Jonas Nicklas - MIT LICENSE

Instance Method Summary collapse

Instance Method Details

#button(locator) ⇒ Object

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

Parameters:

  • locator (String)

    Value, title, id, or image alt attribute of the button



26
27
28
29
30
31
# File 'lib/webdrone/xpath.rb', line 26

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

Parameters:

  • locator (String)

    Label, id, or name of the checkbox to match



94
95
96
97
# File 'lib/webdrone/xpath.rb', line 94

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.

Parameters:

  • locator (String)

    Id of the ‘dd’ element or text from preciding ‘dt’ element content



155
156
157
158
# File 'lib/webdrone/xpath.rb', line 155

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

Parameters:

  • locator (String)

    Label, id, or name of field to match



58
59
60
61
62
63
# File 'lib/webdrone/xpath.rb', line 58

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.

Parameters:

  • locator (String)

    Legend or id of the fieldset



47
48
49
50
# File 'lib/webdrone/xpath.rb', line 47

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

Parameters:

  • locator (String)

    Label, id, or name of the file field to match



114
115
116
117
# File 'lib/webdrone/xpath.rb', line 114

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

Parameters:

  • locator (String)

    Label, id, or name of field to match



72
73
74
75
76
77
# File 'lib/webdrone/xpath.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.

Parameters:

  • locator (String)

    Text, id, title, or image alt attribute of the link



15
16
17
18
19
# File 'lib/webdrone/xpath.rb', line 15

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.

Parameters:

  • locator (String)

    Text, id, title, or image alt attribute of the link or button



38
39
40
# File 'lib/webdrone/xpath.rb', line 38

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

#optgroup(locator) ⇒ Object

Match an ‘optgroup` element.

Parameters:

  • name (String)

    Label for the option group



124
125
126
127
# File 'lib/webdrone/xpath.rb', line 124

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

#option(locator) ⇒ Object

Match an ‘option` element.

Parameters:

  • name (String)

    Visible text of the option



134
135
136
137
# File 'lib/webdrone/xpath.rb', line 134

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

Parameters:

  • locator (String)

    Label, id, or name of the radio button to match



104
105
106
107
# File 'lib/webdrone/xpath.rb', line 104

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.

Parameters:

  • locator (String)

    Label, id, or name of the field to match



84
85
86
87
# File 'lib/webdrone/xpath.rb', line 84

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

#table(locator) ⇒ Object

Match any ‘table` element.

Parameters:

  • locator (String)

    Caption or id of the table to match

  • options (Hash)

    a customizable set of options



146
147
148
149
# File 'lib/webdrone/xpath.rb', line 146

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