Module: WDA::FindElement
- Included in:
- WDA
- Defined in:
- lib/wda_lib/find_element.rb
Instance Method Summary collapse
-
#accessibility_id(value) ⇒ Hash
Search with given accessibility_id.
-
#accessibility_ids(value) ⇒ Array
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 all buttons If value is string then return the all buttons which contain 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 first 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 all icons If value is string then return the all icons which contain given value.
-
#id(value) ⇒ Hash
Search with given id.
-
#ids(value) ⇒ Array
Search all element with given id.
-
#last_button ⇒ Hash
Find the last Button.
-
#last_textfield ⇒ TextField
Find the last TextField.
-
#name(value) ⇒ Hash
Search with given name.
-
#names(value) ⇒ Array
Search all element with given name.
-
#partial_text(value) ⇒ Hash
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’.
-
#searchfield(value = 0) ⇒ Hash, Element
Find SearchField by given index or value If value is integer then return the SearchField at that index If value is string then return the first SearchField which has given value as name.
-
#searchfields(value = nil) ⇒ Array
Find icons by given index or value If value is integer then return all SearchFields If value is string then return the all SearchFields which have given value as name.
-
#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.
- #set_timeout(second) ⇒ Object
-
#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(value = nil) ⇒ Array
Find the all StaticText.
-
#stringlize(instring) ⇒ String
Turn symbol to string, replace ‘_’ to ‘ ’.
-
#text(value) ⇒ Hash
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(value = nil) ⇒ 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) ⇒ Hash
Search with given accessibility_id
112 113 114 |
# File 'lib/wda_lib/find_element.rb', line 112 def accessibility_id(value) find :accessibility_id, value end |
#accessibility_ids(value) ⇒ Array
Search all element with given accessibility_id
119 120 121 |
# File 'lib/wda_lib/find_element.rb', line 119 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
210 211 212 213 214 215 216 |
# File 'lib/wda_lib/find_element.rb', line 210 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 all buttons If value is string then return the all buttons which contain given value
223 224 225 226 227 228 229 |
# File 'lib/wda_lib/find_element.rb', line 223 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
154 155 156 |
# File 'lib/wda_lib/find_element.rb', line 154 def class_name(value) find :class_name, match(value) end |
#class_names(value) ⇒ Array
Search with class name
161 162 163 |
# File 'lib/wda_lib/find_element.rb', line 161 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
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/wda_lib/find_element.rb', line 12 def find(type, value) wait = Wait.new(:timeout => @timeout) # seconds begin wait.until { @element = post('/element', { using: stringlize(type), value: value }) @element['status'] == 0 } ensure raise Error::NoSuchElementError, "Can't find '#{value}' with type '#{type}'" if @element['status'] != 0 end 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
382 383 384 |
# File 'lib/wda_lib/find_element.rb', line 382 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
389 390 391 |
# File 'lib/wda_lib/find_element.rb', line 389 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
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/wda_lib/find_element.rb', line 48 def find_subl_element(id, type, value) wait = Wait.new(:timeout => @timeout) # seconds begin wait.until { @element = post('/element/' + id + '/element', { using: stringlize(type), value: value }) @element['status'] == 0 } ensure raise Error::NoSuchElementError, "Can't find '#{value}' with type '#{type}'" if @element['status'] != 0 end Element.new self, @element['value'] end |
#find_subl_elements(id, type, value) ⇒ Array<Element>
Find children elements by given type and value, return elements array
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/wda_lib/find_element.rb', line 65 def find_subl_elements(id, type, value) wait = Wait.new(:timeout => @timeout) # seconds begin wait.until { @result = post('/element/' + id + '/elements', { using: stringlize(type), value: value }) @elements = @result['value'] @result['status'] != 7 } ensure raise Error::NoSuchElementError, "Can't find '#{value}' with type '#{type}'" if @result['status'] != 0 end @elements.map { |element| Element.new self, element } end |
#finds(type, value) ⇒ Array
Find all elements with given type and value, return in an Array
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/wda_lib/find_element.rb', line 30 def finds(type, value) wait = Wait.new(:timeout => @timeout) # seconds begin wait.until { @elements = post('/elements', { using: stringlize(type), value: value })['value'] @elements.length != 0 } ensure raise Error::NoSuchElementError, "Can't find '#{value}' with type '#{type}'" if @elements.length == 0 end @elements.map { |element| Element.new self, element } end |
#first_button ⇒ Hash
Find the first Button
233 234 235 |
# File 'lib/wda_lib/find_element.rb', line 233 def finds(:xpath, "//XCUIElementTypeButton").first end |
#first_textfield ⇒ TextField
Find the first TextField.
271 272 273 |
# File 'lib/wda_lib/find_element.rb', line 271 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
331 332 333 334 335 336 337 |
# File 'lib/wda_lib/find_element.rb', line 331 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 all icons If value is string then return the all icons which contain given value
344 345 346 347 348 349 350 |
# File 'lib/wda_lib/find_element.rb', line 344 def icons(value = nil) if value.nil? finds(:xpath, "//XCUIElementTypeIcon") else finds(:xpath, "//XCUIElementTypeIcon[@name=\"#{value}\"]") end end |
#id(value) ⇒ Hash
Search with given id
98 99 100 |
# File 'lib/wda_lib/find_element.rb', line 98 def id(value) find :id, value end |
#ids(value) ⇒ Array
Search all element with given id
105 106 107 |
# File 'lib/wda_lib/find_element.rb', line 105 def ids(value) finds :id, value end |
#last_button ⇒ Hash
Find the last Button
239 240 241 |
# File 'lib/wda_lib/find_element.rb', line 239 def finds(:xpath, "//XCUIElementTypeButton").last end |
#last_textfield ⇒ TextField
Find the last TextField.
277 278 279 |
# File 'lib/wda_lib/find_element.rb', line 277 def last_textfield finds(:xpath, "//XCUIElementTypeTextField").last end |
#name(value) ⇒ Hash
Search with given name
84 85 86 |
# File 'lib/wda_lib/find_element.rb', line 84 def name(value) find :name, value end |
#names(value) ⇒ Array
Search all element with given name
91 92 93 |
# File 'lib/wda_lib/find_element.rb', line 91 def names(value) finds :name, value end |
#partial_text(value) ⇒ Hash
Search with given partial value (partial link text)
140 141 142 |
# File 'lib/wda_lib/find_element.rb', line 140 def partial_text(value) find :partial_link_text, "label=#{value}" end |
#partial_texts(value) ⇒ Array
Search with given partial value (partial link text)
147 148 149 |
# File 'lib/wda_lib/find_element.rb', line 147 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’
188 189 190 |
# File 'lib/wda_lib/find_element.rb', line 188 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’
196 197 198 |
# File 'lib/wda_lib/find_element.rb', line 196 def predicate_texts(predicate_value) finds :predicate_string, predicate_value end |
#searchfield(value = 0) ⇒ Hash, Element
Find SearchField by given index or value If value is integer then return the SearchField at that index If value is string then return the first SearchField which has given value as name
357 358 359 360 361 362 363 |
# File 'lib/wda_lib/find_element.rb', line 357 def searchfield(value = 0) if value.is_a? Numeric finds(:xpath, "//XCUIElementTypeSearchField")[value] else find(:xpath, "//XCUIElementTypeSearchField[@name=\"#{value}\"]") end end |
#searchfields(value = nil) ⇒ Array
Find icons by given index or value If value is integer then return all SearchFields If value is string then return the all SearchFields which have given value as name
370 371 372 373 374 375 376 |
# File 'lib/wda_lib/find_element.rb', line 370 def searchfields(value = nil) if value.nil? finds(:xpath, "//XCUIElementTypeSearchField") else finds(:xpath, "//XCUIElementTypeSearchField[@name=\"#{value}\"]") end 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
286 287 288 289 290 291 292 |
# File 'lib/wda_lib/find_element.rb', line 286 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.
296 297 298 |
# File 'lib/wda_lib/find_element.rb', line 296 def secure_textfields finds(:xpath, "//XCUIElementTypeSecureTextField") end |
#set_timeout(second) ⇒ Object
407 408 409 |
# File 'lib/wda_lib/find_element.rb', line 407 def set_timeout(second) @timeout = second 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
305 306 307 308 309 310 311 |
# File 'lib/wda_lib/find_element.rb', line 305 def statictext(value = 0) if value.is_a? Numeric finds(:xpath, "//XCUIElementTypeStaticText")[value] else find(:xpath, "//XCUIElementTypeStaticText[@value=\"#{value}\"]") end end |
#statictexts(value = nil) ⇒ Array
Find the all StaticText. If value is integer then return all StaticTexts If value is string then return the all StaticTexts which contain given value
318 319 320 321 322 323 324 |
# File 'lib/wda_lib/find_element.rb', line 318 def statictexts(value = nil) if value.nil? finds(:xpath, "//XCUIElementTypeStaticText") else finds(:xpath, "//XCUIElementTypeStaticText[@value=\"#{value}\"]") end end |
#stringlize(instring) ⇒ String
Turn symbol to string, replace ‘_’ to ‘ ’
397 398 399 400 401 402 403 404 405 |
# File 'lib/wda_lib/find_element.rb', line 397 def stringlize(instring) if instring.is_a? Symbol instring.to_s.gsub('_', ' ') elsif instring.is_a? String return instring.gsub('_', ' ') else fail 'Xpath searching type should be a String' end end |
#text(value) ⇒ Hash
Search with given value (Complete value)
126 127 128 |
# File 'lib/wda_lib/find_element.rb', line 126 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
248 249 250 251 252 253 254 |
# File 'lib/wda_lib/find_element.rb', line 248 def textfield(value = 0) if value.is_a? Numeric finds(:xpath, "//XCUIElementTypeTextField")[value] else find(:xpath, "//XCUIElementTypeTextField[@value=\"#{value}\"]") end end |
#textfields(value = nil) ⇒ Array
Find the all TextField. If value is integer then return all textFields If value is string then return all textFields which contain given value
261 262 263 264 265 266 267 |
# File 'lib/wda_lib/find_element.rb', line 261 def textfields(value = nil) if value.nil? finds(:xpath, "//XCUIElementTypeTextField") else finds(:xpath, "//XCUIElementTypeTextField[@value=\"#{value}\"]") end end |
#texts(value) ⇒ Array
Search with given value (Complete value)
133 134 135 |
# File 'lib/wda_lib/find_element.rb', line 133 def texts(value) finds :link_text, "label=#{value}" end |
#visible_cell(id) ⇒ Object
Returns element’s visible cells [Array].
201 202 203 |
# File 'lib/wda_lib/find_element.rb', line 201 def visible_cell(id) get '/uiaElement/' + id + '/getVisibleCells' end |
#xpath(value) ⇒ Array
Search with xpath example: “//XCUIElementTypeButton”, “//XCUIElementTypeTextField”
171 172 173 |
# File 'lib/wda_lib/find_element.rb', line 171 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”
180 181 182 |
# File 'lib/wda_lib/find_element.rb', line 180 def xpath_search(type, attribute, value) finds :xpath, "//#{match(type)}[@#{attribute}=\"#{value}\"]" end |