- Defined in:
#all([kind], locator, options) ⇒ 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. It's set to :css by default.
page.all("a#person_123") . = :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.
205 206 207 208 209 210 211 212
# File 'lib/capybara/node/finders.rb', line 205 def all(*args) query = ::::.(*args) synchronize(query.wait) do result = query.resolve_for(self) raise ::, result. unless result.matches_count? result end end