1
1
module Appium
2
2
module Ios
3
- UIATextField = 'UIATextField'
3
+ UIATextField = 'UIATextField'
4
4
UIASecureTextField = 'UIASecureTextField'
5
- # Get an array of textfield elements.
6
- # @return [Array<Textfield>]
7
- def e_textfields
8
- xpaths %Q(//#{ UIATextField } [@visible="true"] | //#{ UIASecureTextField } [@visible="true"])
5
+
6
+ # @private
7
+ def _textfield_visible_string opts = { }
8
+ index = opts . fetch :index , false
9
+ if index
10
+ %Q(//#{ UIATextField } [@visible="true"][#{ index } ] | //#{ UIASecureTextField } [@visible="true"][#{ index } ])
11
+ else
12
+ %Q(//#{ UIATextField } [@visible="true"] | //#{ UIASecureTextField } [@visible="true"])
13
+ end
9
14
end
10
15
11
- # Get the first textfield element.
12
- # @return [Textfield]
13
- def first_textfield
14
- xpath %Q(//#{ UIATextField } [@visible="true"] | //#{ UIASecureTextField } [@visible="true"])
16
+ # @private
17
+ def _textfield_exact_string value
18
+ textfield = string_visible_exact UIATextField , value
19
+ secure = string_visible_exact UIASecureTextField , value
20
+ "#{ textfield } | #{ secure } "
15
21
end
16
22
17
- # Get the last textfield element.
18
- # @return [Textfield]
19
- def last_textfield
20
- xpath %Q(//#{ UIATextField } [@visible="true"][last()] | //#{ UIASecureTextField } [@visible="true"][last()])
23
+ # @private
24
+ def _textfield_contains_string value
25
+ textfield = string_visible_contains UIATextField , value
26
+ secure = string_visible_contains UIASecureTextField , value
27
+ "#{ textfield } | #{ secure } "
21
28
end
22
29
23
30
# Get the first textfield that matches text.
24
- # @param text [String, Integer] the text to match exactly. If int then the textfield at that index is returned.
31
+ # @param value [String, Integer] the text to match exactly. If int then the textfield at that index is returned.
25
32
# @return [Textfield]
26
33
def textfield value
27
34
# Don't use ele_index because that only works on one element type.
@@ -30,34 +37,43 @@ def textfield value
30
37
index = value
31
38
raise "#{ index } is not a valid xpath index. Must be >= 1" if index <= 0
32
39
33
- return xpath ( %Q(// #{ UIATextField } [@visible="true"][ #{ index } ] | // #{ UIASecureTextField } [@visible="true"][ #{ index } ]) )
40
+ return xpath _textfield_visible_string index : index
34
41
end
35
42
36
- textfield_include value
43
+ xpath _textfield_contains_string value
37
44
end
38
45
39
46
def textfields value
40
- textfield = string_visible_include UIATextField , value
41
- secure = string_visible_include UIASecureTextField , value
42
- xpaths "#{ textfield } | #{ secure } "
47
+ xpaths _textfield_contains_string value
43
48
end
44
49
45
- # Get the first textfield that includes text.
46
- # @param value [String] the value the textfield must include
50
+ # Get the first textfield element.
47
51
# @return [Textfield]
48
- def textfield_include value
49
- textfield = string_visible_include UIATextField , value
50
- secure = string_visible_include UIASecureTextField , value
51
- xpath "#{ textfield } | #{ secure } "
52
+ def first_textfield
53
+ xpath _textfield_visible_string
54
+ end
55
+
56
+ # Get the last textfield element.
57
+ # @return [Textfield]
58
+ def last_textfield
59
+ xpath _textfield_visible_string index : 'last()'
52
60
end
53
61
54
62
# Get the first textfield that exactly matches text.
55
63
# @param value [String] the value the textfield must exactly match
56
64
# @return [Textfield]
57
65
def textfield_exact value
58
- textfield = string_visible_exact UIATextField , value
59
- secure = string_visible_exact UIASecureTextField , value
60
- xpath "#{ textfield } | #{ secure } "
66
+ xpath _textfield_exact_string value
67
+ end
68
+
69
+ def textfields_exact value
70
+ xpaths _textfield_exact_string value
71
+ end
72
+
73
+ # Get an array of textfield elements.
74
+ # @return [Array<Textfield>]
75
+ def e_textfields
76
+ xpaths _textfield_visible_string
61
77
end
62
78
end # module Ios
63
79
end # module Appium
0 commit comments