@@ -59,6 +59,7 @@ def all_ele_js predicate
59
59
# @param text [String] the text to search for
60
60
# @return [Element] the first matching element
61
61
def find text
62
+ text = escape_single_quote text
62
63
ele = nil
63
64
# prefer value search. this may error with:
64
65
# Can't use in/contains operator with collection 1
@@ -81,6 +82,7 @@ def find text
81
82
# @param text [String] the text to search for
82
83
# @return [Array<Element>] all matching elements
83
84
def finds text
85
+ text = escape_single_quote text
84
86
eles = [ ]
85
87
# value contains may error
86
88
js = all_ele_js "value contains[c] '#{ text } '"
@@ -95,6 +97,7 @@ def finds text
95
97
# @param text [String] the text to search for
96
98
# @return [Element] the first matching element
97
99
def text text
100
+ text = escape_single_quote text
98
101
js = first_ele_js "value contains[c] '#{ text } '"
99
102
execute_script js
100
103
end
@@ -103,6 +106,7 @@ def text text
103
106
# @param text [String] the text to search for
104
107
# @return [Array<Element>] all matching elements
105
108
def texts text
109
+ text = escape_single_quote text
106
110
# XPath //* is not implemented on iOS
107
111
# https://github.com/appium/appium/issues/430
108
112
js = all_ele_js "value contains[c] '#{ text } '"
@@ -115,10 +119,12 @@ def texts text
115
119
# @param name [String] the name to search for
116
120
# @return [Element] the first matching element
117
121
def name name
122
+ name = escape_single_quote name
118
123
mobile :findElementNameContains , name : name
119
124
end
120
125
121
126
def name_exact name
127
+ name = escape_single_quote name
122
128
js = all_ele_js "name == '#{ name } '"
123
129
result = execute_script js
124
130
@@ -137,9 +143,14 @@ def name_exact name
137
143
# @param name [String] the name to search for
138
144
# @return [Array<Element>] all matching elements
139
145
def names name
146
+ name = escape_single_quote name
140
147
# :name is not consistent across iOS and Android so use custom JavaScript
141
148
# https://github.com/appium/appium/issues/379
142
149
js = all_ele_js "name contains[c] '#{ name } ' || label contains[c] '#{ name } '"
143
150
execute_script js
144
151
end
152
+
153
+ def escape_single_quote text_to_escape
154
+ text_to_escape . gsub ( "'" , '\\' * 4 + "'" )
155
+ end
145
156
end # module Appium::Ios
0 commit comments