Method: Capybara::Node::Finders#all

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

- (Capybara::Result) all([kind], locator, options)

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)

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)

    Only find elements that are visible on the page. Setting this to false finds invisible and visible elements.

  • exact (Boolean)

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

Returns:



128
129
130
# File 'lib/capybara/node/finders.rb', line 128

def all(*args)
  resolve_query(Capybara::Query.new(*args))
end

Comments