Module: Webdrone::XPath
Overview
Code from teamcapybara/xpath Copyright © 2016 Jonas Nicklas - MIT LICENSE
Instance Method Summary collapse
-
#button(locator) ⇒ Object
Match a ‘submit`, `image`, or `button` element.
-
#checkbox(locator) ⇒ Object
Match any ‘input` element of type `checkbox`.
-
#definition_description(locator) ⇒ Object
Match any ‘dd’ element.
-
#field(locator) ⇒ Object
Match any ‘input`, `textarea`, or `select` element that doesn’t have a type of ‘submit`, `image`, or `hidden`.
-
#fieldset(locator) ⇒ Object
Match any ‘fieldset` element.
-
#file_field(locator) ⇒ Object
Match any ‘input` element of type `file`.
-
#fillable_field(locator) ⇒ Object
Match any ‘input` or `textarea` element that can be filled with text.
-
#link(locator) ⇒ Object
Match an ‘a` link element.
- #link_or_button(locator) ⇒ Object
-
#optgroup(locator) ⇒ Object
Match an ‘optgroup` element.
-
#option(locator) ⇒ Object
Match an ‘option` element.
-
#radio_button(locator) ⇒ Object
Match any ‘input` element of type `radio`.
-
#select(locator) ⇒ Object
Match any ‘select` element.
-
#table(locator) ⇒ Object
Match any ‘table` element.
Instance Method Details
#button(locator) ⇒ Object
Match a ‘submit`, `image`, or `button` element.
26 27 28 29 30 31 |
# File 'lib/webdrone/xpath.rb', line 26 def (locator) locator = locator.to_s = descendant(:input)[attr(:type).one_of('submit', 'reset', 'image', 'button')][attr(:id).equals(locator) | attr(:value).is(locator) | attr(:title).is(locator)] += descendant(:button)[attr(:id).equals(locator) | attr(:value).is(locator) | string.n.is(locator) | attr(:title).is(locator)] + descendant(:input)[attr(:type).equals('image')][attr(:alt).is(locator)] end |
#checkbox(locator) ⇒ Object
Match any ‘input` element of type `checkbox`.
92 93 94 95 |
# File 'lib/webdrone/xpath.rb', line 92 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.
153 154 155 156 |
# File 'lib/webdrone/xpath.rb', line 153 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`.
58 59 60 61 62 |
# 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')] locate_field(xpath, locator) end |
#fieldset(locator) ⇒ Object
Match any ‘fieldset` element.
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`.
112 113 114 115 |
# File 'lib/webdrone/xpath.rb', line 112 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`.
71 72 73 74 75 |
# File 'lib/webdrone/xpath.rb', line 71 def fillable_field(locator) locator = locator.to_s xpath = descendant(:input, :textarea)[~attr(:type).one_of('submit', 'image', 'radio', 'checkbox', 'hidden', 'file')] locate_field(xpath, locator) end |
#link(locator) ⇒ Object
Match an ‘a` link element.
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 |
#link_or_button(locator) ⇒ Object
38 39 40 |
# File 'lib/webdrone/xpath.rb', line 38 def (locator) link(locator) + (locator) end |
#optgroup(locator) ⇒ Object
Match an ‘optgroup` element.
122 123 124 125 |
# File 'lib/webdrone/xpath.rb', line 122 def optgroup(locator) locator = locator.to_s descendant(:optgroup)[attr(:label).is(locator)] end |
#option(locator) ⇒ Object
Match an ‘option` element.
132 133 134 135 |
# File 'lib/webdrone/xpath.rb', line 132 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`.
102 103 104 105 |
# File 'lib/webdrone/xpath.rb', line 102 def (locator) locator = locator.to_s locate_field(descendant(:input)[attr(:type).equals('radio')], locator) end |
#select(locator) ⇒ Object
Match any ‘select` element.
82 83 84 85 |
# File 'lib/webdrone/xpath.rb', line 82 def select(locator) locator = locator.to_s locate_field(descendant(:select), locator) end |
#table(locator) ⇒ Object
Match any ‘table` element.
144 145 146 147 |
# File 'lib/webdrone/xpath.rb', line 144 def table(locator) locator = locator.to_s descendant(:table)[attr(:id).equals(locator) | descendant(:caption).is(locator)] end |