@@ -177,11 +177,7 @@ def page_window window_number=0
177
177
# @param id [String] the id to search for
178
178
# @return [Element]
179
179
def id id
180
- value = resolve_id id
181
- raise "Invalid id `#{ id } `" unless value
182
- exact = string_visible_exact '*' , value
183
- contains = string_visible_contains '*' , value
184
- xpath "#{ exact } | #{ contains } "
180
+ find_element :id , id
185
181
end
186
182
187
183
# Return the iOS version as an array of integers
@@ -283,41 +279,41 @@ def tags class_name
283
279
# @private
284
280
# Returns a string xpath that matches the first element that contains value
285
281
#
286
- # example: xpath_visible_contains 'UIATextField', 'sign in'
282
+ # example: ele_by_json_visible_contains 'UIATextField', 'sign in'
287
283
#
288
284
# @param element [String] the class name for the element
289
285
# @param value [String] the value to search for
290
286
# @return [String]
291
287
def string_visible_contains element , value
292
- result = [ ]
293
- attributes = %w[ name hint label value ]
294
-
295
- value_up = value . upcase
296
- value_down = value . downcase
297
-
298
- attributes . each do |attribute |
299
- result << %Q(contains(translate(@#{ attribute } ,"#{ value_up } ","#{ value_down } "), "#{ value_down } "))
300
- end
288
+ contains = {
289
+ target : value ,
290
+ substring : true ,
291
+ insensitive : true ,
292
+ }
301
293
302
- result = result . join ( ' or ' )
303
- result = %Q(@visible="true" and (#{ result } ))
304
- "//#{ element } [#{ result } ]"
294
+ {
295
+ typeArray : [ element ] ,
296
+ onlyVisible : true ,
297
+ name : contains ,
298
+ label : contains ,
299
+ value : contains ,
300
+ }
305
301
end
306
302
307
303
# Find the first element that contains value
308
304
# @param element [String] the class name for the element
309
305
# @param value [String] the value to search for
310
306
# @return [Element]
311
- def xpath_visible_contains element , value
312
- xpath string_visible_contains element , value
307
+ def ele_by_json_visible_contains element , value
308
+ ele_by_json string_visible_contains element , value
313
309
end
314
310
315
311
# Find all elements containing value
316
312
# @param element [String] the class name for the element
317
313
# @param value [String] the value to search for
318
314
# @return [Array<Element>]
319
- def xpaths_visible_contains element , value
320
- xpaths string_visible_contains element , value
315
+ def eles_by_json_visible_contains element , value
316
+ eles_by_json string_visible_contains element , value
321
317
end
322
318
323
319
# @private
@@ -326,33 +322,35 @@ def xpaths_visible_contains element, value
326
322
# @param value [String] the value to search for
327
323
# @return [String]
328
324
def string_visible_exact element , value
329
- result = [ ]
330
- attributes = %w[ name hint label value ]
331
-
332
- attributes . each do |attribute |
333
- result << %Q(@#{ attribute } ="#{ value } ")
334
- end
335
-
336
- result = result . join ( ' or ' )
337
- result = %Q(@visible="true" and (#{ result } ))
325
+ exact = {
326
+ target : value ,
327
+ substring : false ,
328
+ insensitive : false ,
329
+ }
338
330
339
- "//#{ element } [#{ result } ]"
331
+ {
332
+ typeArray : [ element ] ,
333
+ onlyVisible : true ,
334
+ name : exact ,
335
+ label : exact ,
336
+ value : exact ,
337
+ }
340
338
end
341
339
342
340
# Find the first element exactly matching value
343
341
# @param element [String] the class name for the element
344
342
# @param value [String] the value to search for
345
343
# @return [Element]
346
- def xpath_visible_exact element , value
347
- xpath string_visible_exact element , value
344
+ def ele_by_json_visible_exact element , value
345
+ ele_by_json string_visible_exact element , value
348
346
end
349
347
350
348
# Find all elements exactly matching value
351
349
# @param element [String] the class name for the element
352
350
# @param value [String] the value to search for
353
351
# @return [Element]
354
- def xpaths_visible_exact element , value
355
- xpaths string_visible_exact element , value
352
+ def eles_by_json_visible_exact element , value
353
+ eles_by_json string_visible_exact element , value
356
354
end
357
355
358
356
# @private
@@ -448,7 +446,7 @@ def _validate_object *objects
448
446
objects . each do |obj |
449
447
next unless obj # obj may be nil. if so, ignore.
450
448
451
- valid_keys = [ :target , :substring , :insensitive ]
449
+ valid_keys = [ :target , :substring , :insensitive ]
452
450
unknown_keys = obj . keys - valid_keys
453
451
raise "Unknown keys: #{ unknown_keys } " unless unknown_keys . empty?
454
452
@@ -492,7 +490,7 @@ def _validate_object *objects
492
490
# }
493
491
#
494
492
def _by_json opts
495
- valid_keys = [ :typeArray , :onlyFirst , :onlyVisible , :name , :label , :value ]
493
+ valid_keys = [ :typeArray , :onlyFirst , :onlyVisible , :name , :label , :value ]
496
494
unknown_keys = opts . keys - valid_keys
497
495
raise "Unknown keys: #{ unknown_keys } " unless unknown_keys . empty?
498
496
@@ -539,7 +537,7 @@ def eles_by_json opts
539
537
# see eles_by_json
540
538
def ele_by_json opts
541
539
opts [ :onlyFirst ] = true
542
- result = _by_json ( opts ) . first
540
+ result = _by_json ( opts ) . first
543
541
raise _no_such_element if result . nil?
544
542
result
545
543
end
0 commit comments