Module: WDA::FindElement

Included in:
WDA
Defined in:
lib/wda_lib/find_element.rb

Instance Method Summary collapse

Instance Method Details

#accessibility_id(value) ⇒ Hash

Search with given accessibility_id

Parameters:

  • value (String)

Returns:

  • (Hash)


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

Parameters:

  • value (String)

Returns:

  • (Array)


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

Parameters:

  • value (String, Integer) (defaults to: 0)

Returns:



210
211
212
213
214
215
216
# File 'lib/wda_lib/find_element.rb', line 210

def button(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

Parameters:

  • value (String, Integer) (defaults to: nil)

Returns:

  • (Array)

    All found buttons



223
224
225
226
227
228
229
# File 'lib/wda_lib/find_element.rb', line 223

def buttons(value = nil)
  if value.nil?
    finds(:xpath, "//XCUIElementTypeButton")
  else
    finds(:xpath, "//XCUIElementTypeButton[@name=\"#{value}\"]")
  end
end

#class_name(value) ⇒ Hash

Search with class name

Parameters:

  • value (String)

    XCUIElementType*, class name in XCUITest, ex: class_names(‘Button’) to search XCUIElementTypeButton

Returns:

  • (Hash)

    found XCUIElementType* elements



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

Parameters:

  • value (String)

    XCUIElementType*, class name in XCUITest, ex: class_names(‘Button’) to search XCUIElementTypeButton

Returns:

  • (Array)

    contains all XCUIElementType* elements



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

Parameters:

  • type (String, Symbol)

    , value [Stirng]

Returns:

  • (Hash)


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

Parameters:

  • args (*args)

Returns:

  • (Object)


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

Parameters:

  • args (*args)

Returns:



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

Parameters:

  • id (String)

    parent element id, type [String, Symbol], value [Stirng]

Returns:

  • (Object)

    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

Parameters:

  • id (String)

    parent element id, type [String, Symbol], value [Stirng]

Returns:



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

Parameters:

  • type (String, Symbol)

    , value [Stirng]

Returns:

  • (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_buttonHash

Find the first Button

Returns:

  • (Hash)

    button



233
234
235
# File 'lib/wda_lib/find_element.rb', line 233

def first_button
  finds(:xpath, "//XCUIElementTypeButton").first
end

#first_textfieldTextField

Find the first TextField.

Returns:

  • (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

Parameters:

  • value (String, Integer) (defaults to: 0)

Returns:



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

Parameters:

  • value (String) (defaults to: nil)

Returns:

  • (Array)

    All found icons



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

Parameters:

  • value (String)

Returns:

  • (Hash)


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

Parameters:

  • value (String)

Returns:

  • (Array)


105
106
107
# File 'lib/wda_lib/find_element.rb', line 105

def ids(value)
  finds :id, value
end

#last_buttonHash

Find the last Button

Returns:

  • (Hash)

    button



239
240
241
# File 'lib/wda_lib/find_element.rb', line 239

def last_button
  finds(:xpath, "//XCUIElementTypeButton").last
end

#last_textfieldTextField

Find the last TextField.

Returns:

  • (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

Parameters:

  • value (String)

Returns:

  • (Hash)


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

Parameters:

  • value (String)

Returns:

  • (Array)


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)

Parameters:

  • value (String)

Returns:

  • (Hash)


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)

Parameters:

  • value (String)

Returns:

  • (Array)


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’

Parameters:

  • predicate_value (String)

    ‘isWDVisible=1’

Returns:

  • (Hash)


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’

Parameters:

  • predicate_value (String)

    ‘isWDVisible=1’

Returns:

  • (Array)


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

Parameters:

  • value (String, Integer) (defaults to: 0)

Returns:



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

Parameters:

  • value (String) (defaults to: nil)

Returns:

  • (Array)

    All found SearchFields



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

Parameters:

  • value (String, Integer) (defaults to: 0)

Returns:

  • (TextField)


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_textfieldsArray

Find the all SecureTextField.

Returns:

  • (Array)


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

Parameters:

  • value (String, Integer) (defaults to: 0)

Returns:

  • (TextField)


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

Parameters:

  • value (String) (defaults to: nil)

Returns:

  • (Array)


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 ‘ ’

Parameters:

  • instring (Symbol)

Returns:

  • (String)


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)

Parameters:

  • value (String)

Returns:

  • (Hash)


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

Parameters:

  • value (String, Integer) (defaults to: 0)

Returns:

  • (TextField)


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

Parameters:

  • value (String) (defaults to: nil)

Returns:

  • (Array)


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)

Parameters:

  • value (String)

Returns:

  • (Array)


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

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

Parameters:

  • value (String)

Returns:

  • (Array)

    contains all elements which match given xpath



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

Parameters:

  • type (String)

    , attribute [String], value [String]

Returns:

  • (Array)

    contains all elements which match given variables



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