lib/capybara/node/finders.rb in capybara-1.1.2 vs lib/capybara/node/finders.rb in capybara-1.1.3

- old
+ new

@@ -22,11 +22,11 @@ # @option options [String] :message An error message in case the element can't be found # @return [Capybara::Element] The found element # @raise [Capybara::ElementNotFound] If the element can't be found before time expires # def find(*args) - wait_until { first(*args) or raise_find_error(*args) } + wait_until { first(*args) or raise_find_error(*args) }.tap(&:allow_reload!) end ## # # Find a form field on the page. The field can be found by its name, id or label text. @@ -105,13 +105,13 @@ # @option options [String, Regexp] text Only find elements which contain this text or match this regexp # @option options [Boolean] visible Only find elements that are visible on the page # @return [Capybara::Element] The found elements # def all(*args) + selector = Capybara::Selector.normalize(*args) options = extract_normalized_options(args) - selector = Capybara::Selector.normalize(*args) selector.xpaths. map { |path| find_in_base(selector, path) }.flatten. select { |node| matches_options(node, options) } end @@ -127,14 +127,14 @@ # @param [String] locator The selector # @param [Hash{Symbol => Object}] options Additional options; see {all} # @return Capybara::Element The found element # def first(*args) + selector = Capybara::Selector.normalize(*args) options = extract_normalized_options(args) found_elements = [] - selector = Capybara::Selector.normalize(*args) selector.xpaths.each do |path| find_in_base(selector, path).each do |node| if matches_options(node, options) found_elements << node return found_elements.last if not Capybara.prefer_visible_elements or node.visible? @@ -177,16 +177,18 @@ options end def matches_options(node, options) - return false if options[:text] and not node.text.match(options[:text]) - return false if options[:visible] and not node.visible? - return false if options[:with] and not node.value == options[:with] - return false if options[:checked] and not node.checked? - return false if options[:unchecked] and node.checked? - return false if options[:selected] and not has_selected_options?(node, options[:selected]) - true + node.without_wait do + return false if options[:text] and not node.text.match(options[:text]) + return false if options[:visible] and not node.visible? + return false if options[:with] and not node.value == options[:with] + return false if options[:checked] and not node.checked? + return false if options[:unchecked] and node.checked? + return false if options[:selected] and not has_selected_options?(node, options[:selected]) + true + end end def has_selected_options?(node, expected) actual = node.all(:xpath, './/option').select { |option| option.selected? }.map { |option| option.text } (expected - actual).empty?