@@ -39,12 +39,16 @@ def scroll_uiselector(content, index = 0)
39
39
# @return [Element] the element scrolled to
40
40
def scroll_to ( text , scrollable_index = 0 )
41
41
text = %("#{ text } ")
42
-
43
- args = scroll_uiselector ( "new UiSelector().textContains(#{ text } )" , scrollable_index ) +
44
- scroll_uiselector ( "new UiSelector().descriptionContains(#{ text } )" , scrollable_index ) +
45
- scroll_uiselector ( resource_id ( text , "new UiSelector().resourceId(#{ text } );" ) , scrollable_index )
46
-
47
- find_element :uiautomator , args
42
+ rid = resource_id ( text , "new UiSelector().resourceId(#{ text } );" )
43
+ args = rid . empty? ? [ "new UiSelector().textContains(#{ text } )" , "new UiSelector().descriptionContains(#{ text } )" ] : [ rid ]
44
+ args . each_with_index do |arg , index |
45
+ begin
46
+ elem = find_element :uiautomator , scroll_uiselector ( arg , scrollable_index )
47
+ return elem
48
+ rescue => e
49
+ raise e if index == args . size - 1
50
+ end
51
+ end
48
52
end
49
53
50
54
# Scroll to the first element with the exact target text or description.
@@ -53,12 +57,16 @@ def scroll_to(text, scrollable_index = 0)
53
57
# @return [Element] the element scrolled to
54
58
def scroll_to_exact ( text , scrollable_index = 0 )
55
59
text = %("#{ text } ")
56
-
57
- args = scroll_uiselector ( "new UiSelector().text(#{ text } )" , scrollable_index ) +
58
- scroll_uiselector ( "new UiSelector().description(#{ text } )" , scrollable_index ) +
59
- scroll_uiselector ( resource_id ( text , "new UiSelector().resourceId(#{ text } );" ) , scrollable_index )
60
-
61
- find_element :uiautomator , args
60
+ rid = resource_id ( text , "new UiSelector().resourceId(#{ text } );" )
61
+ args = rid . empty? ? [ "new UiSelector().text(#{ text } )" , "new UiSelector().description(#{ text } )" ] : [ rid ]
62
+ args . each_with_index do |arg , index |
63
+ begin
64
+ elem = find_element :uiautomator , scroll_uiselector ( arg , scrollable_index )
65
+ return elem
66
+ rescue => e
67
+ raise e if index == args . size - 1
68
+ end
69
+ end
62
70
end
63
71
end # module Android
64
72
end # module Appium
0 commit comments