Skip to content

Commit 82f9c58

Browse files
Fix value contains operator
1 parent c5b8d84 commit 82f9c58

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lib/appium_lib/common/helper.rb

+5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ def wait max_wait=30, interval=0.5, &block
4141
result
4242
end
4343

44+
# Return block.call and ignore any exceptions.
45+
def ignore &block
46+
begin; block.call; rescue; end
47+
end
48+
4449
# Check every 0.5 seconds to see if block.call returns true. nil is considered a failure.
4550
# Give up after 30 seconds.
4651
# @param max_wait [Integer] the maximum time in seconds to wait for

lib/appium_lib/ios/element/generic.rb

+16-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,22 @@ def all_ele_js predicate
5959
# @param text [String] the text to search for
6060
# @return [Element] the first matching element
6161
def find text
62-
js = first_ele_js "name contains[c] '#{text}' || label contains[c] '#{text}' || value contains[c] '#{text}'"
63-
execute_script js
62+
ele = nil
63+
# prefer value search. this may error with:
64+
# Can't use in/contains operator with collection 1
65+
js = first_ele_js "value contains[c] '#{text}'"
66+
ignore { ele = execute_script js }
67+
68+
# now search name and label if the value search didn't match.
69+
unless ele
70+
js = first_ele_js "name contains[c] '#{text}' || label contains[c] '#{text}'"
71+
ignore { ele ||= execute_script js }
72+
end
73+
74+
# manually raise error if no element was found
75+
raise Selenium::WebDriver::Error::NoSuchElementError, 'An element could not be located on the page using the given search parameters.' unless ele
76+
77+
ele
6478
end
6579

6680
# Return all elements matching text.

0 commit comments

Comments
 (0)