lib/appium_lib/ios/element/generic.rb in appium_lib-0.18.2 vs lib/appium_lib/ios/element/generic.rb in appium_lib-0.19.0

- old
+ new

@@ -57,10 +57,11 @@ # Return the first element matching text. # @param text [String] the text to search for # @return [Element] the first matching element def find text + text = escape_single_quote text ele = nil # prefer value search. this may error with: # Can't use in/contains operator with collection 1 js = first_ele_js "value contains[c] '#{text}'" ele = ignore { execute_script js } @@ -79,10 +80,11 @@ # Return all elements matching text. # @param text [String] the text to search for # @return [Array<Element>] all matching elements def finds text + text = escape_single_quote text eles = [] # value contains may error js = all_ele_js "value contains[c] '#{text}'" eles = ignore { execute_script js } @@ -93,34 +95,47 @@ # Return the first element matching text. # @param text [String] the text to search for # @return [Element] the first matching element def text text + text = escape_single_quote text js = first_ele_js "value contains[c] '#{text}'" execute_script js end # Return all elements matching text. # @param text [String] the text to search for # @return [Array<Element>] all matching elements def texts text + text = escape_single_quote text # XPath //* is not implemented on iOS # https://github.com/appium/appium/issues/430 js = all_ele_js "value contains[c] '#{text}'" execute_script js end # Return the first element matching name. # on Android name is content description # on iOS name is the accessibility label or the text. + # + # ```ruby + # # find element with name or label containing example and access the name attribute. + # name('example').name + # + # # find element with name or label containing example and access the label attribute. + # name('example').label + # ``` + # # @param name [String] the name to search for # @return [Element] the first matching element def name name + name = escape_single_quote name mobile :findElementNameContains, name: name end def name_exact name + name = escape_single_quote name js = all_ele_js "name == '#{name}'" result = execute_script js return result if result.kind_of? Selenium::WebDriver::Element @@ -135,11 +150,16 @@ # on Android name is content description # on iOS name is the accessibility label or the text. # @param name [String] the name to search for # @return [Array<Element>] all matching elements def names name + name = escape_single_quote name # :name is not consistent across iOS and Android so use custom JavaScript # https://github.com/appium/appium/issues/379 js = all_ele_js "name contains[c] '#{name}' || label contains[c] '#{name}'" execute_script js end -end # module Appium::Ios \ No newline at end of file + + def escape_single_quote text_to_escape + text_to_escape.gsub("'", '\\' * 4 + "'") + end +end # module Appium::Ios