Module: WDA::FindElement

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

Instance Method Summary collapse

Instance Method Details

#accessibility_id(value) ⇒ Object

Search with given accessibility_id

Parameters:

  • value (String)


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

Parameters:

  • value (String)


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

Parameters:

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

Returns:



167
168
169
170
171
172
173
# File 'lib/wda_lib/find_element.rb', line 167

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 button at that index If value is string then return the all button which contains given value

Parameters:

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

Returns:

  • (Array)

    All found buttons



180
181
182
183
184
185
186
# File 'lib/wda_lib/find_element.rb', line 180

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



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

Parameters:

  • value (String)

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

Returns:

  • (Array)

    contains all XCUIElementType* elements



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

Parameters:

  • type (String, Symbol)

    , value [Stirng]

Returns:

  • (Hash)


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

Parameters:

  • args (*args)

Returns:

  • (Object)


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

Parameters:

  • args (*args)

Returns:



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

Parameters:

  • id (String)

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

Returns:

  • (Object)

    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

Parameters:

  • id (String)

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

Returns:



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

Parameters:

  • type (String, Symbol)

    , value [Stirng]

Returns:

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

Find the first Button

Returns:

  • (Hash)

    button



190
191
192
# File 'lib/wda_lib/find_element.rb', line 190

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

#first_textfieldTextField

Find the last TextField.

Returns:

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

Parameters:

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

Returns:



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

Parameters:

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

Returns:

  • (Array)

    All found icons



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

Parameters:

  • value (String)


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

Parameters:

  • value (String)


62
63
64
# File 'lib/wda_lib/find_element.rb', line 62

def ids(value)
  finds :id, value
end

#last_buttonHash

Find the last Button

Returns:

  • (Hash)

    button



196
197
198
# File 'lib/wda_lib/find_element.rb', line 196

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

#name(value) ⇒ Object

Search with given name

Parameters:

  • value (String)


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

Parameters:

  • value (String)


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)

Parameters:

  • value (String)


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)

Parameters:

  • value (String)

Returns:

  • (Array)


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’

Parameters:

  • value (String)

    ‘isWDVisible=1’

Returns:

  • (Hash)


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’

Parameters:

  • value (String)

    ‘isWDVisible=1’

Returns:

  • (Array)


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

Parameters:

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

Returns:

  • (TextField)


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_textfieldsArray

Find the all SecureTextField.

Returns:

  • (Array)


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

Parameters:

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

Returns:

  • (TextField)


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

#statictextsArray

Find the all StaticText.

Returns:

  • (Array)


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

Parameters:

  • instring (Symbol)

Returns:

  • (String)


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)

Parameters:

  • value (String)


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

Parameters:

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

Returns:

  • (TextField)


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

#textfieldsArray

Find the all TextField.

Returns:

  • (Array)


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)

Parameters:

  • value (String)

Returns:

  • (Array)


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

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

Parameters:

  • value (String)

Returns:

  • (Array)

    contains all elements which match given xpath



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

Parameters:

  • type (String)

    , attribute [String], value [String]

Returns:

  • (Array)

    contains all elements which match given variables



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