Skip to content

Instantly share code, notes, and snippets.

@mschuerig
Created November 21, 2013 08:13
Show Gist options
  • Save mschuerig/7577756 to your computer and use it in GitHub Desktop.
Save mschuerig/7577756 to your computer and use it in GitHub Desktop.
within_any. Helper method for capybara. For selectors matching multiple elements, expect the block not to raise an error for one of them.
def within_any(*args)
candidates = page.all(*args)
if candidates.empty?
query = Capybara::Query.new(*args)
raise Capybara::ElementNotFound.new("Unable to find #{query.description}")
end
error = nil
candidates.any? do
begin
yield
return
rescue => e
error = e
end
end
raise error
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment