@@ -286,35 +286,31 @@ def resource_id(string, on_match)
286286 # @param value [String] the value to search for
287287 # @return [String]
288288 def string_visible_contains ( class_name , value )
289- value = %(" #{ value } ")
289+ r_id = resource_id ( value , " or @resource-id=' #{ value } ' ")
290290
291291 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 + ']'
295294 end
296295
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 + ']'
302298 end
303299
304300 # Find the first element that contains value
305301 # @param element [String] the class name for the element
306302 # @param value [String] the value to search for
307303 # @return [Element]
308304 def complex_find_contains ( element , value )
309- find_element :uiautomator , string_visible_contains ( element , value )
305+ find_element :xpath , string_visible_contains ( element , value )
310306 end
311307
312308 # Find all elements containing value
313309 # @param element [String] the class name for the element
314310 # @param value [String] the value to search for
315311 # @return [Array<Element>]
316312 def complex_finds_contains ( element , value )
317- find_elements :uiautomator , string_visible_contains ( element , value )
313+ find_elements :xpath , string_visible_contains ( element , value )
318314 end
319315
320316 # @private
@@ -323,35 +319,29 @@ def complex_finds_contains(element, value)
323319 # @param value [String] the value to search for
324320 # @return [String]
325321 def string_visible_exact ( class_name , value )
326- value = %(" #{ value } ")
322+ r_id = resource_id ( value , " or @resource-id=' #{ value } ' ")
327323
328324 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 + ']'
332326 end
333327
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 + ']'
339329 end
340330
341331 # Find the first element exactly matching value
342332 # @param class_name [String] the class name for the element
343333 # @param value [String] the value to search for
344334 # @return [Element]
345335 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 )
347337 end
348338
349339 # Find all elements exactly matching value
350340 # @param class_name [String] the class name for the element
351341 # @param value [String] the value to search for
352342 # @return [Element]
353343 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 )
355345 end
356346
357347 # Returns XML string for the current page
0 commit comments