99name defaults to label when undefined. value is never a default so that must be
1010included in a new search.
1111
12+ Find - search everything.
13+
1214The search order is:
13151. name
14162. label (implied by name)
15173. value
18+
1619=end
1720
1821# Return the first element matching text.
1922# @param text [String] the text to search for
2023# @return [Element] the first matching element
21- def text text
24+ def find text
2225 # returnElems requires a wrapped $(element).
2326 # set to empty array when length is zero to prevent hang.
2427 js = %Q(
2528 var eles = au.mainWindow.elements();
26- var a = eles.firstWithPredicate("name contains[c] '#{ text } '");
29+ var a = eles.firstWithPredicate("name contains[c] '#{ text } ' || label contains[c] ' #{ text } ' || value contains[c] ' #{ text } ' ");
2730 if ( a.length === 0 ) {
28- a = eles.firstWithPredicate("value contains[c] '#{ text } '");
29- if ( a.length === 0 ) {
30- a = [];
31- }
31+ a = [];
3232 }
3333 au._returnElems($(a));
3434 )
@@ -39,13 +39,12 @@ def text text
3939# Return all elements matching text.
4040# @param text [String] the text to search for
4141# @return [Array<Element>] all matching elements
42- def texts text
42+ def finds text
4343 # returnElems requires a wrapped $(element).
4444 # must call toArray when using withPredicate instead of firstWithPredicate.
4545 js = %Q(
4646 var eles = au.mainWindow.elements();
47- var a = eles.withPredicate("name contains[c] '#{ text } '").toArray();
48- a = a.concat( eles.withPredicate("value contains[c] '#{ text } '").toArray() );
47+ var a = eles.withPredicate("name contains[c] '#{ text } ' || label contains[c] '#{ text } ' || value contains[c] '#{ text } '").toArray();
4948 if ( a.length === 0 ) {
5049 a = [];
5150 }
@@ -55,22 +54,4 @@ def texts text
5554 execute_script js
5655end
5756
58- # Return the first element matching name.
59- # on Android name is content description
60- # on iOS name is the accessibility label or the text.
61- # @param name [String] the name to search for
62- # @return [Element] the first matching element
63- def name name
64- text name
65- end
66-
67- # Return all elements matching name.
68- # on Android name is content description
69- # on iOS name is the accessibility label or the text.
70- # @param name [String] the name to search for
71- # @return [Array<Element>] all matching elements
72- def names name
73- texts name
74- end
75-
7657end # if ios
0 commit comments