Module: WDA::FindElement

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

Instance Method Summary collapse

Instance Method Details

#button(value = 0) ⇒ Button

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



120
121
122
123
124
125
126
# File 'lib/wda_lib/find_element.rb', line 120

def button(value = 0)
  if value.is_a? Numeric
    finds(:xpath, "//XCUIElementTypeButton")[value]
  else
    find(:xpath, "//XCUIElementTypeButton[@name='#{value}']")
  end
end

#buttonsHash



129
130
131
# File 'lib/wda_lib/find_element.rb', line 129

def buttons
  finds(:xpath, "//XCUIElementTypeButton")
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



218
219
220
# File 'lib/wda_lib/find_element.rb', line 218

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



225
226
227
# File 'lib/wda_lib/find_element.rb', line 225

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_buttonHash

Find the first Button



135
136
137
# File 'lib/wda_lib/find_element.rb', line 135

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

#first_textfieldTextField

Find the last TextField.



166
167
168
# File 'lib/wda_lib/find_element.rb', line 166

def first_textfield
  finds(:xpath, "//XCUIElementTypeTextField").first
end

#last_buttonHash

Find the last Button



141
142
143
# File 'lib/wda_lib/find_element.rb', line 141

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

#name(class_name) ⇒ Array

Search with class name



69
70
71
# File 'lib/wda_lib/find_element.rb', line 69

def name(class_name)
  finds :class_name, class_name
end

#partial_text(value) ⇒ Object

Search with given partial value (partial link text)



55
56
57
# File 'lib/wda_lib/find_element.rb', line 55

def partial_text(value)
  find :partial_link_text, "label=#{value}"
end

#partial_texts(value) ⇒ Array

Search with given partial value (partial link text)



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

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’



96
97
98
# File 'lib/wda_lib/find_element.rb', line 96

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’



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

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



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

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.



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

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



200
201
202
203
204
205
206
# File 'lib/wda_lib/find_element.rb', line 200

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.



210
211
212
# File 'lib/wda_lib/find_element.rb', line 210

def statictexts
  finds(:xpath, "//XCUIElementTypeStaticText")
end

#stringlize(instring) ⇒ String

Turn symbol to string, replace ‘_’ to ‘ ’



233
234
235
236
237
238
239
240
241
# File 'lib/wda_lib/find_element.rb', line 233

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)



41
42
43
# File 'lib/wda_lib/find_element.rb', line 41

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



150
151
152
153
154
155
156
# File 'lib/wda_lib/find_element.rb', line 150

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.



160
161
162
# File 'lib/wda_lib/find_element.rb', line 160

def textfields
  finds(:xpath, "//XCUIElementTypeTextField")
end

#texts(value) ⇒ Array

Search with given value (Complete value)



48
49
50
# File 'lib/wda_lib/find_element.rb', line 48

def texts(value)
  finds :link_text, "label=#{value}"
end

#visible_cell(id) ⇒ Object



110
111
112
# File 'lib/wda_lib/find_element.rb', line 110

def visible_cell(id)
  get '/uiaElement/' + id + '/getVisibleCells'
end

#xpath(value) ⇒ Array

Search with xpath example: “//XCUIElementTypeButton”, “//XCUIElementTypeTextField



79
80
81
# File 'lib/wda_lib/find_element.rb', line 79

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



88
89
90
# File 'lib/wda_lib/find_element.rb', line 88

def xpath_search(type, attribute, value)
  finds :xpath, "//#{match(type)}[@#{attribute}='#{value}']"
end