@@ -286,35 +286,31 @@ def resource_id(string, on_match)
286
286
# @param value [String] the value to search for
287
287
# @return [String]
288
288
def string_visible_contains ( class_name , value )
289
- value = %(" #{ value } ")
289
+ r_id = resource_id ( value , " or @resource-id=' #{ value } ' ")
290
290
291
291
if class_name == '*'
292
- return ( resource_id ( value , "new UiSelector().resourceId(#{ value } );" ) +
293
- "new UiSelector().descriptionContains(#{ value } );" \
294
- "new UiSelector().textContains(#{ value } );" )
292
+ return "//*[contains(translate(@text,'#{ value . upcase } ', '#{ value } '), '#{ value } ')" \
293
+ " or contains(translate(@content-desc,'#{ value . upcase } ', '#{ value } '), '#{ value } ')" + r_id + ']'
295
294
end
296
295
297
- class_name = %("#{ class_name } ")
298
-
299
- resource_id ( value , "new UiSelector().className(#{ class_name } ).resourceId(#{ value } );" ) +
300
- "new UiSelector().className(#{ class_name } ).descriptionContains(#{ value } );" \
301
- "new UiSelector().className(#{ class_name } ).textContains(#{ value } );"
296
+ "//#{ class_name } [contains(translate(@text,'#{ value . upcase } ', '#{ value } '), '#{ value } ')" \
297
+ " or contains(translate(@content-desc,'#{ value . upcase } ', '#{ value } '), '#{ value } ')" + r_id + ']'
302
298
end
303
299
304
300
# Find the first element that contains value
305
301
# @param element [String] the class name for the element
306
302
# @param value [String] the value to search for
307
303
# @return [Element]
308
304
def complex_find_contains ( element , value )
309
- find_element :uiautomator , string_visible_contains ( element , value )
305
+ find_element :xpath , string_visible_contains ( element , value )
310
306
end
311
307
312
308
# Find all elements containing value
313
309
# @param element [String] the class name for the element
314
310
# @param value [String] the value to search for
315
311
# @return [Array<Element>]
316
312
def complex_finds_contains ( element , value )
317
- find_elements :uiautomator , string_visible_contains ( element , value )
313
+ find_elements :xpath , string_visible_contains ( element , value )
318
314
end
319
315
320
316
# @private
@@ -323,35 +319,29 @@ def complex_finds_contains(element, value)
323
319
# @param value [String] the value to search for
324
320
# @return [String]
325
321
def string_visible_exact ( class_name , value )
326
- value = %(" #{ value } ")
322
+ r_id = resource_id ( value , " or @resource-id=' #{ value } ' ")
327
323
328
324
if class_name == '*'
329
- return ( resource_id ( value , "new UiSelector().resourceId(#{ value } );" ) +
330
- "new UiSelector().description(#{ value } );" \
331
- "new UiSelector().text(#{ value } );" )
325
+ return "//*[@text='#{ value } ' or @content-desc='#{ value } '" + r_id + ']'
332
326
end
333
327
334
- class_name = %("#{ class_name } ")
335
-
336
- resource_id ( value , "new UiSelector().className(#{ class_name } ).resourceId(#{ value } );" ) +
337
- "new UiSelector().className(#{ class_name } ).description(#{ value } );" \
338
- "new UiSelector().className(#{ class_name } ).text(#{ value } );"
328
+ "//#{ class_name } [@text='#{ value } ' or @content-desc='#{ value } '" + r_id + ']'
339
329
end
340
330
341
331
# Find the first element exactly matching value
342
332
# @param class_name [String] the class name for the element
343
333
# @param value [String] the value to search for
344
334
# @return [Element]
345
335
def complex_find_exact ( class_name , value )
346
- find_element :uiautomator , string_visible_exact ( class_name , value )
336
+ find_element :xpath , string_visible_exact ( class_name , value )
347
337
end
348
338
349
339
# Find all elements exactly matching value
350
340
# @param class_name [String] the class name for the element
351
341
# @param value [String] the value to search for
352
342
# @return [Element]
353
343
def complex_finds_exact ( class_name , value )
354
- find_elements :uiautomator , string_visible_exact ( class_name , value )
344
+ find_elements :xpath , string_visible_exact ( class_name , value )
355
345
end
356
346
357
347
# Returns XML string for the current page
0 commit comments