@@ -6,27 +6,41 @@ module Ios
6
6
private
7
7
8
8
# @private
9
- def _textfield_visible_string opts = { }
10
- index = opts . fetch :index , false
11
- if index
12
- %Q((//#{ UIATextField } [@visible="true"])[#{ index } ] | (//#{ UIASecureTextField } [@visible="true"])[#{ index } ])
13
- else
14
- %Q(//#{ UIATextField } [@visible="true"] | //#{ UIASecureTextField } [@visible="true"])
15
- end
9
+ def _textfield_visible
10
+ {
11
+ typeArray : [ UIATextField , UIASecureTextField ] ,
12
+ onlyVisible : true ,
13
+ }
16
14
end
17
15
18
16
# @private
19
17
def _textfield_exact_string value
20
- textfield = string_visible_exact UIATextField , value
21
- secure = string_visible_exact UIASecureTextField , value
22
- "#{ textfield } | #{ secure } "
18
+ exact = {
19
+ target : value ,
20
+ substring : false ,
21
+ insensitive : false ,
22
+ }
23
+ exact_obj = {
24
+ name : exact ,
25
+ label : exact ,
26
+ value : exact ,
27
+ }
28
+ _textfield_visible . merge ( exact_obj )
23
29
end
24
30
25
31
# @private
26
32
def _textfield_contains_string value
27
- textfield = string_visible_contains UIATextField , value
28
- secure = string_visible_contains UIASecureTextField , value
29
- "#{ textfield } | #{ secure } "
33
+ contains = {
34
+ target : value ,
35
+ substring : true ,
36
+ insensitive : true ,
37
+ }
38
+ contains_obj = {
39
+ name : contains ,
40
+ label : contains ,
41
+ value : contains ,
42
+ }
43
+ _textfield_visible . merge ( contains_obj )
30
44
end
31
45
32
46
public
@@ -40,47 +54,51 @@ def textfield value
40
54
# iOS needs to combine textfield and secure to match Android.
41
55
if value . is_a? Numeric
42
56
index = value
43
- raise "#{ index } is not a valid xpath index. Must be >= 1" if index <= 0
57
+ raise "#{ index } is not a valid index. Must be >= 1" if index <= 0
44
58
45
- return xpath _textfield_visible_string index : index
59
+ result = eles_by_json ( _textfield_visible ) [ index ]
60
+ raise _no_such_element if result . nil?
61
+ return result
46
62
end
47
63
48
- xpath _textfield_contains_string value
64
+ ele_by_json _textfield_contains_string value
49
65
end
50
66
51
67
# Find all TextFields containing value.
52
68
# If value is omitted, all TextFields are returned.
53
69
# @param value [String] the value to search for
54
70
# @return [Array<TextField>]
55
71
def textfields value = false
56
- return xpaths _textfield_visible_string unless value
57
- xpaths _textfield_contains_string value
72
+ return eles_by_json _textfield_visible unless value
73
+ eles_by_json _textfield_contains_string value
58
74
end
59
75
60
76
# Find the first TextField.
61
77
# @return [TextField]
62
78
def first_textfield
63
- xpath _textfield_visible_string
79
+ ele_by_json _textfield_visible
64
80
end
65
81
66
82
# Find the last TextField.
67
83
# @return [TextField]
68
84
def last_textfield
69
- xpath _textfield_visible_string index : 'last()'
85
+ result = eles_by_json ( _textfield_visible ) . last
86
+ raise _no_such_element if result . nil?
87
+ result
70
88
end
71
89
72
90
# Find the first TextField that exactly matches value.
73
91
# @param value [String] the value to match exactly
74
92
# @return [TextField]
75
93
def textfield_exact value
76
- xpath _textfield_exact_string value
94
+ ele_by_json _textfield_exact_string value
77
95
end
78
96
79
97
# Find all TextFields that exactly match value.
80
98
# @param value [String] the value to match exactly
81
99
# @return [Array<TextField>]
82
100
def textfields_exact value
83
- xpaths _textfield_exact_string value
101
+ eles_by_json _textfield_exact_string value
84
102
end
85
103
end # module Ios
86
104
end # module Appium
0 commit comments