Module: WDA::FindElement
- Included in:
- WDA
- Defined in:
- lib/wda_lib/find_element.rb
Instance Method Summary collapse
-
#accessibility_id(value) ⇒ Object
Search with given accessibility_id.
-
#accessibility_ids(value) ⇒ Object
Search all element with given accessibility_id.
-
#button(value = 0) ⇒ Hash, Element
Find button by given index or value If value is integer then return the button at that index If value is string then return the first button which contains given value.
-
#buttons(value = nil) ⇒ Array
Find buttons by given index or value If value is integer then return the button at that index If value is string then return the all button which contains given value.
-
#class_name(value) ⇒ Hash
Search with class name.
-
#class_names(value) ⇒ Array
Search with class name.
-
#find(type, value) ⇒ Hash
Find element with given type and value, return first found element.
-
#find_element(*args) ⇒ Object
This is calling selenium find_element* methods########## Find element with given type and value, return first found element.
-
#find_elements(*args) ⇒ Array<Element>
Find elements with given type and value, return in an Array.
-
#find_subl_element(id, type, value) ⇒ Object
Find child element by given type and value, return first found element.
-
#find_subl_elements(id, type, value) ⇒ Array<Element>
Find children elements by given type and value, return elements array.
-
#finds(type, value) ⇒ Array
Find all elements with given type and value, return in an Array.
-
#first_button ⇒ Hash
Find the first Button.
-
#first_textfield ⇒ TextField
Find the last TextField.
-
#icon(value = 0) ⇒ Hash, Element
Find icon by given index or value If value is integer then return the icon at that index If value is string then return the first icon which contains given value.
-
#icons(value = nil) ⇒ Array
Find icons by given index or value If value is integer then return the icon at that index If value is string then return the all icons which contains given value.
-
#id(value) ⇒ Object
Search with given id.
-
#ids(value) ⇒ Object
Search all element with given id.
-
#last_button ⇒ Hash
Find the last Button.
-
#name(value) ⇒ Object
Search with given name.
-
#names(value) ⇒ Object
Search all element with given name.
-
#partial_text(value) ⇒ Object
Search with given partial value (partial link text).
-
#partial_texts(value) ⇒ Array
Search with given partial value (partial link text).
-
#predicate_text(predicate_value) ⇒ Hash
Search predicate string, return first found element example: ‘isWDAccessible=1’, ‘isWDEnabled=0’.
-
#predicate_texts(predicate_value) ⇒ Array
Search with predicate string example: ‘isWDAccessible=1’, ‘isWDEnabled=0’, ‘isWDAccessibilityContainer=1’.
-
#secure_textfield(value = 0) ⇒ TextField
Find secure_textfield by given index or value If value is integer then return the secure_textField at that index If value is string then return the first secure_textField which contains given value.
-
#secure_textfields ⇒ Array
Find the all SecureTextField.
-
#statictext(value = 0) ⇒ TextField
Find StaticText by given index or value If value is integer then return the StaticText at that index If value is string then return the first StaticText which contains given value.
-
#statictexts ⇒ Array
Find the all StaticText.
-
#stringlize(instring) ⇒ String
Turn symbol to string, replace ‘_’ to ‘ ’.
-
#text(value) ⇒ Object
Search with given value (Complete value).
-
#textfield(value = 0) ⇒ TextField
Find textfield by given index or value If value is integer then return the textField at that index If value is string then return the first textField which contains given value.
-
#textfields ⇒ Array
Find the all TextField.
-
#texts(value) ⇒ Array
Search with given value (Complete value).
-
#visible_cell(id) ⇒ Object
Element’s visible cells [Array].
-
#xpath(value) ⇒ Array
Search with xpath example: “//XCUIElementTypeButton”, “//XCUIElementTypeTextField”.
-
#xpath_search(type, attribute, value) ⇒ Array
Xpath search with element type, element attribute, element attribute value example: xpath(‘Button’, ‘name’, ‘Share’) for “//XCUIElementTypeButton”.
Instance Method Details
#accessibility_id(value) ⇒ Object
Search with given accessibility_id
69 70 71 |
# File 'lib/wda_lib/find_element.rb', line 69 def accessibility_id(value) find :accessibility_id, value end |
#accessibility_ids(value) ⇒ Object
Search all element with given accessibility_id
76 77 78 |
# File 'lib/wda_lib/find_element.rb', line 76 def accessibility_ids(value) finds :accessibility_id, value end |
#button(value = 0) ⇒ Hash, Element
Find button by given index or value If value is integer then return the button at that index If value is string then return the first button which contains given value
167 168 169 170 171 172 173 |
# File 'lib/wda_lib/find_element.rb', line 167 def (value = 0) if value.is_a? Numeric finds(:xpath, "//XCUIElementTypeButton")[value] else find(:xpath, "//XCUIElementTypeButton[@name='#{value}']") end end |
#buttons(value = nil) ⇒ Array
Find buttons by given index or value If value is integer then return the button at that index If value is string then return the all button which contains given value
180 181 182 183 184 185 186 |
# File 'lib/wda_lib/find_element.rb', line 180 def (value = nil) if value.nil? finds(:xpath, "//XCUIElementTypeButton") else finds(:xpath, "//XCUIElementTypeButton[@name='#{value}']") end end |
#class_name(value) ⇒ Hash
Search with class name
111 112 113 |
# File 'lib/wda_lib/find_element.rb', line 111 def class_name(value) find :class_name, match(value) end |
#class_names(value) ⇒ Array
Search with class name
118 119 120 |
# File 'lib/wda_lib/find_element.rb', line 118 def class_names(value) finds :class_name, match(value) end |
#find(type, value) ⇒ Hash
Find element with given type and value, return first found element
8 9 10 11 12 |
# File 'lib/wda_lib/find_element.rb', line 8 def find(type, value) element = post('/element', { using: stringlize(type), value: value }) fail "Can't find #{value} with type #{type}" if element['status'] !=0 Element.new self, element['value'] end |
#find_element(*args) ⇒ Object
This is calling selenium find_element* methods########## Find element with given type and value, return first found element
299 300 301 |
# File 'lib/wda_lib/find_element.rb', line 299 def find_element(*args) @driver.find_element(*args) end |
#find_elements(*args) ⇒ Array<Element>
Find elements with given type and value, return in an Array
306 307 308 |
# File 'lib/wda_lib/find_element.rb', line 306 def find_elements(*args) @driver.find_elements(*args) end |
#find_subl_element(id, type, value) ⇒ Object
Find child element by given type and value, return first found element
25 26 27 28 |
# File 'lib/wda_lib/find_element.rb', line 25 def find_subl_element(id, type, value) element = post('/element/' + id + '/element', { using: type, value: value }) Element.new self, element['ELEMENT'] end |
#find_subl_elements(id, type, value) ⇒ Array<Element>
Find children elements by given type and value, return elements array
33 34 35 36 |
# File 'lib/wda_lib/find_element.rb', line 33 def find_subl_elements(id, type, value) elements = post('/element/' + id + '/elements', { using: type, value: value }) elements.map { |element| Element.new self, element['ELEMENT'] } end |
#finds(type, value) ⇒ Array
Find all elements with given type and value, return in an Array
17 18 19 20 |
# File 'lib/wda_lib/find_element.rb', line 17 def finds(type, value) elements = post('/elements', { using: stringlize(type), value: value })['value'] elements.map { |element| Element.new self, element } end |
#first_button ⇒ Hash
Find the first Button
190 191 192 |
# File 'lib/wda_lib/find_element.rb', line 190 def finds(:xpath, "//XCUIElementTypeButton").first end |
#first_textfield ⇒ TextField
Find the last TextField.
221 222 223 |
# File 'lib/wda_lib/find_element.rb', line 221 def first_textfield finds(:xpath, "//XCUIElementTypeTextField").first end |
#icon(value = 0) ⇒ Hash, Element
Find icon by given index or value If value is integer then return the icon at that index If value is string then return the first icon which contains given value
274 275 276 277 278 279 280 |
# File 'lib/wda_lib/find_element.rb', line 274 def icon(value = 0) if value.is_a? Numeric finds(:xpath, "//XCUIElementTypeIcon")[value] else find :xpath, "//XCUIElementTypeIcon[@name='#{value}']" end end |
#icons(value = nil) ⇒ Array
Find icons by given index or value If value is integer then return the icon at that index If value is string then return the all icons which contains given value
287 288 289 290 291 292 293 |
# File 'lib/wda_lib/find_element.rb', line 287 def icons(value = nil) if value.nil? finds(:xpath, "//XCUIElementTypeIcon") else finds :xpath, "//XCUIElementTypeIcon[@name='#{value}']" end end |
#id(value) ⇒ Object
Search with given id
55 56 57 |
# File 'lib/wda_lib/find_element.rb', line 55 def id(value) find :id, value end |
#ids(value) ⇒ Object
Search all element with given id
62 63 64 |
# File 'lib/wda_lib/find_element.rb', line 62 def ids(value) finds :id, value end |
#last_button ⇒ Hash
Find the last Button
196 197 198 |
# File 'lib/wda_lib/find_element.rb', line 196 def finds(:xpath, "//XCUIElementTypeButton").last end |
#name(value) ⇒ Object
Search with given name
41 42 43 |
# File 'lib/wda_lib/find_element.rb', line 41 def name(value) find :name, value end |
#names(value) ⇒ Object
Search all element with given name
48 49 50 |
# File 'lib/wda_lib/find_element.rb', line 48 def names(value) finds :name, value end |
#partial_text(value) ⇒ Object
Search with given partial value (partial link text)
97 98 99 |
# File 'lib/wda_lib/find_element.rb', line 97 def partial_text(value) find :partial_link_text, "label=#{value}" end |
#partial_texts(value) ⇒ Array
Search with given partial value (partial link text)
104 105 106 |
# File 'lib/wda_lib/find_element.rb', line 104 def partial_texts(value) finds :partial_link_text, "label=#{value}" end |
#predicate_text(predicate_value) ⇒ Hash
Search predicate string, return first found element example: ‘isWDAccessible=1’, ‘isWDEnabled=0’
145 146 147 |
# File 'lib/wda_lib/find_element.rb', line 145 def predicate_text(predicate_value) find :predicate_string, predicate_value end |
#predicate_texts(predicate_value) ⇒ Array
Search with predicate string example: ‘isWDAccessible=1’, ‘isWDEnabled=0’, ‘isWDAccessibilityContainer=1’
153 154 155 |
# File 'lib/wda_lib/find_element.rb', line 153 def predicate_texts(predicate_value) finds :predicate_string, predicate_value end |
#secure_textfield(value = 0) ⇒ TextField
Find secure_textfield by given index or value If value is integer then return the secure_textField at that index If value is string then return the first secure_textField which contains given value
236 237 238 239 240 241 242 |
# File 'lib/wda_lib/find_element.rb', line 236 def secure_textfield(value = 0) if value.is_a? Numeric finds(:xpath, "//XCUIElementTypeSecureTextField")[value] else find :xpath, "//XCUIElementTypeSecureTextField[@value='#{value}']" end end |
#secure_textfields ⇒ Array
Find the all SecureTextField.
246 247 248 |
# File 'lib/wda_lib/find_element.rb', line 246 def secure_textfields finds(:xpath, "//XCUIElementTypeSecureTextField") end |
#statictext(value = 0) ⇒ TextField
Find StaticText by given index or value If value is integer then return the StaticText at that index If value is string then return the first StaticText which contains given value
255 256 257 258 259 260 261 |
# File 'lib/wda_lib/find_element.rb', line 255 def statictext(value = 0) if value.is_a? Numeric finds(:xpath, "//XCUIElementTypeStaticText")[value] else find :xpath, "//XCUIElementTypeStaticText[@value='#{value}']" end end |
#statictexts ⇒ Array
Find the all StaticText.
265 266 267 |
# File 'lib/wda_lib/find_element.rb', line 265 def statictexts finds(:xpath, "//XCUIElementTypeStaticText") end |
#stringlize(instring) ⇒ String
Turn symbol to string, replace ‘_’ to ‘ ’
314 315 316 317 318 319 320 321 322 |
# File 'lib/wda_lib/find_element.rb', line 314 def stringlize(instring) if instring.is_a? Symbol instring.to_s.gsub('_', ' ') elsif instring.is_a? String return instring else fail 'Xpath searching type should be a String' end end |
#text(value) ⇒ Object
Search with given value (Complete value)
83 84 85 |
# File 'lib/wda_lib/find_element.rb', line 83 def text(value) find :link_text, "label=#{value}" end |
#textfield(value = 0) ⇒ TextField
Find textfield by given index or value If value is integer then return the textField at that index If value is string then return the first textField which contains given value
205 206 207 208 209 210 211 |
# File 'lib/wda_lib/find_element.rb', line 205 def textfield(value = 0) if value.is_a? Numeric finds(:xpath, "//XCUIElementTypeTextField")[value] else find :xpath, "//XCUIElementTypeTextField[@value='#{value}']" end end |
#textfields ⇒ Array
Find the all TextField.
215 216 217 |
# File 'lib/wda_lib/find_element.rb', line 215 def textfields finds(:xpath, "//XCUIElementTypeTextField") end |
#texts(value) ⇒ Array
Search with given value (Complete value)
90 91 92 |
# File 'lib/wda_lib/find_element.rb', line 90 def texts(value) finds :link_text, "label=#{value}" end |
#visible_cell(id) ⇒ Object
Returns element’s visible cells [Array].
158 159 160 |
# File 'lib/wda_lib/find_element.rb', line 158 def visible_cell(id) get '/uiaElement/' + id + '/getVisibleCells' end |
#xpath(value) ⇒ Array
Search with xpath example: “//XCUIElementTypeButton”, “//XCUIElementTypeTextField”
128 129 130 |
# File 'lib/wda_lib/find_element.rb', line 128 def xpath(value) finds :xpath, value end |
#xpath_search(type, attribute, value) ⇒ Array
Xpath search with element type, element attribute, element attribute value example: xpath(‘Button’, ‘name’, ‘Share’) for “//XCUIElementTypeButton”
137 138 139 |
# File 'lib/wda_lib/find_element.rb', line 137 def xpath_search(type, attribute, value) finds :xpath, "//#{match(type)}[@#{attribute}='#{value}']" end |