Skip to content

Commit aaeba81

Browse files
Add order to find
1 parent 73b757c commit aaeba81

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

lib/appium_lib/element/ios/generic.rb

+35-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
2. label (implied by name)
1717
3. value
1818
19+
The element order is:
20+
1. button
21+
2. textfield
22+
3. secure textfield
23+
4. all elements
1924
=end
2025

2126
# Return the first element matching text.
@@ -24,12 +29,35 @@
2429
def find text
2530
# returnElems requires a wrapped $(element).
2631
# set to empty array when length is zero to prevent hang.
32+
#
33+
# UIAElementNil when not matched
34+
#
35+
# 1. secureTextFields
36+
# 2. textFields
37+
# 3. buttons
38+
# 4. elements
2739
js = %Q(
28-
var eles = au.mainWindow.elements();
29-
var a = eles.firstWithPredicate("name contains[c] '#{text}' || label contains[c] '#{text}' || value contains[c] '#{text}'");
40+
function isNil( a ) {
41+
return a.type() === 'UIAElementNil';
42+
}
43+
44+
var w = au.mainWindow;
45+
var search = "name contains[c] '#{text}' || label contains[c] '#{text}' || value contains[c] '#{text}'";
46+
var a = w.secureTextFields().firstWithPredicate(search);
47+
if ( isNil(a) ) {
48+
a = w.textFields().firstWithPredicate(search);
49+
if ( isNil(a) ) {
50+
a = w.buttons().firstWithPredicate(search);
51+
if ( isNil(a) ) {
52+
a = w.elements().firstWithPredicate(search);
53+
}
54+
}
55+
}
56+
3057
if ( a.length === 0 ) {
3158
a = [];
3259
}
60+
3361
au._returnElems($(a));
3462
)
3563

@@ -43,11 +71,14 @@ def finds text
4371
# returnElems requires a wrapped $(element).
4472
# must call toArray when using withPredicate instead of firstWithPredicate.
4573
js = %Q(
46-
var eles = au.mainWindow.elements();
47-
var a = eles.withPredicate("name contains[c] '#{text}' || label contains[c] '#{text}' || value contains[c] '#{text}'").toArray();
74+
var w = au.mainWindow;
75+
var search = "name contains[c] '#{text}' || label contains[c] '#{text}' || value contains[c] '#{text}'";
76+
var a = w.elements().withPredicate(search).toArray();
77+
4878
if ( a.length === 0 ) {
4979
a = [];
5080
}
81+
5182
au._returnElems($(a));
5283
)
5384

0 commit comments

Comments
 (0)