Method: Capybara::Node::Finders#all

Defined in:
lib/capybara/node/finders.rb

#all([kind], locator, options) ⇒ Capybara::Result Also known as: find_all

Find all elements on the page matching the given selector and options.

Both XPath and CSS expressions are supported, but Capybara does not try to automatically distinguish between them. The following statements are equivalent:

page.all(:css, 'a#person_123')
page.all(:xpath, '//a[@id="person_123"]')

If the type of selector is left out, Capybara uses Capybara.default_selector. It's set to :css by default.

page.all("a#person_123")

Capybara.default_selector = :xpath
page.all('//a[@id="person_123"]')

The set of found elements can further be restricted by specifying options. It's possible to select elements by their text or visibility:

page.all('a', :text => 'Home')
page.all('#menu li', :visible => true)

By default if no elements are found, an empty array is returned; however, expectations can be set on the number of elements to be found which will trigger Capybara's waiting behavior for the expectations to match.The expectations can be set using

page.assert_selector('p#foo', :count => 4)
page.assert_selector('p#foo', :maximum => 10)
page.assert_selector('p#foo', :minimum => 1)
page.assert_selector('p#foo', :between => 1..10)

See Helpers#matches_count? for additional information about count matching.

Parameters:

  • kind (:css, :xpath)

    The type of selector

  • locator (String)

    The selector

Options Hash (options):

  • text (String, Regexp)

    Only find elements which contain this text or match this regexp

  • visible (Boolean, Symbol)

    Only find elements with the specified visibility:

    • true - only finds visible elements.

    • false - finds invisible and visible elements.

    • :all - same as false; finds visible and invisible elements.

    • :hidden - only finds invisible elements.

    • :visible - same as true; only finds visible elements.

  • count (Integer)

    Exact number of matches that are expected to be found

  • maximum (Integer)

    Maximum number of matches that are expected to be found

  • minimum (Integer)

    Minimum number of matches that are expected to be found

  • between (Range)

    Number of matches found must be within the given range

  • exact (Boolean)

    Control whether `is` expressions in the given XPath match exactly or partially

  • wait (Integer) — default: Capybara.default_max_wait_time

    The time to wait for element count expectations to become true

Returns:



173
174
175
176
177
178
179
180
# File 'lib/capybara/node/finders.rb', line 173

def all(*args)
  query = Capybara::Query.new(*args)
  synchronize(query.wait) do
    result = query.resolve_for(self)
    raise Capybara::ExpectationNotMet, result.failure_message unless result.matches_count?
    result
  end
end

Comments