module Capybara::Node::Finders
def all(*args, **options, &optional_filter_block)
-
(Capybara::ExpectationNotMet)
- The number of elements found doesn't match the specified conditions
Returns:
-
(Capybara::Result)
- A collection of found elements
Other tags:
- Yieldreturn: - Should the element be considered in the results?
Other tags:
- Yieldparam: element - The element being considered for inclusion in the results
Overloads:
-
all([kind = Capybara.default_selector], locator = nil, options = {}, &filter_block)
-
all([kind = Capybara.default_selector], locator = nil, options = {})
Options Hash:
(**options)
-
wait
(Integer, false
) -- The time to wait for matching elements to become available -
exact
(Boolean
) -- Control whether `is` expressions in the given XPath match exactly or partially -
between
(Range
) -- Number of matches found must be within the given range -
minimum
(Integer
) -- Minimum number of matches that are expected to be found -
maximum
(Integer
) -- Maximum number of matches that are expected to be found -
count
(Integer
) -- Exact number of matches that are expected to be found -
visible
(Boolean, Symbol
) -- Only find elements with the specified visibility: -
exact_text
(String, Boolean
) -- When String the elements contained text must match exactly, when Boolean controls whether the :text option must match exactly -
text
(String, Regexp
) -- Only find elements which contain this text or match this regexp
Parameters:
-
locator
(String
) -- The locator for the specified selector -
kind
(Symbol
) -- Optional selector type (:css, :xpath, :field, etc.) - Defaults to Capybara.default_selector
def all(*args, **options, &optional_filter_block) minimum_specified = options_include_minimum?(options) options = { minimum: 1 }.merge(options) unless minimum_specified options[:session_options] = session_options query = Capybara::Queries::SelectorQuery.new(*args.push(options), &optional_filter_block) result = nil begin synchronize(query.wait) do result = query.resolve_for(self) raise Capybara::ExpectationNotMet, result.failure_message unless result.matches_count? result end rescue Capybara::ExpectationNotMet raise if minimum_specified || (result.compare_count == 1) Result.new([], nil) end end
def ambiguous?(query, result)
def ambiguous?(query, result) query.match == :one or query.match == :smart and result.size > 1 end
def ancestor(*args, **options, &optional_filter_block)
-
(Capybara::ElementNotFound)
- If the element can't be found before time expires
Returns:
-
(Capybara::Node::Element)
- The found element
Options Hash:
(**options)
-
match
(Boolean
) -- The matching strategy to use.
Parameters:
-
(
) --
def ancestor(*args, **options, &optional_filter_block) options[:session_options] = session_options synced_resolve Capybara::Queries::AncestorQuery.new(*args, **options, &optional_filter_block) end
def find(*args, **options, &optional_filter_block)
-
(Capybara::ElementNotFound)
- If the element can't be found before time expires
Returns:
-
(Capybara::Node::Element)
- The found element
Options Hash:
(**options)
-
match
(Boolean
) -- The matching strategy to use. -
wait
(false, Numeric
) -- Maximum time to wait for matching element to appear.
Parameters:
-
(
) --
def find(*args, **options, &optional_filter_block) options[:session_options] = session_options synced_resolve Capybara::Queries::SelectorQuery.new(*args, options, &optional_filter_block) end
def find_button(locator = nil, **options, &optional_filter_block)
-
(Capybara::Node::Element)
- The found element
Options Hash:
(**options)
-
class
(String, Array
) -- Match buttons that match the class(es) provided -
value
(String
) -- Match buttons with the value provided -
title
(String
) -- Match buttons with the title provided -
id
(String
) -- Match buttons with the id provided -
disabled
(Boolean, Symbol
) -- Match disabled button?
Overloads:
-
find_button(options={})
-
find_button([locator], options={})
Parameters:
-
locator
(String
) -- id, value, title, text content, alt of image
def find_button(locator = nil, **options, &optional_filter_block) find(:button, locator, options, &optional_filter_block) end
def find_by_id(id, **options, &optional_filter_block)
-
(Capybara::Node::Element)
- The found element
Parameters:
-
id
(String
) -- id of element
def find_by_id(id, **options, &optional_filter_block) find(:id, id, options, &optional_filter_block) end
def find_field(locator = nil, **options, &optional_filter_block)
def find_field(locator = nil, **options, &optional_filter_block) find(:field, locator, options, &optional_filter_block) end
def find_link(locator = nil, **options, &optional_filter_block)
-
(Capybara::Node::Element)
- The found element
Options Hash:
(**options)
-
class
(String, Array
) -- Match links that match the class(es) provided -
alt
(String
) -- Match links with a contained img element whose alt matches -
title
(String
) -- Match links with the title provided -
id
(String
) -- Match links with the id provided -
href
(String, Regexp, nil
) -- Value to match against the links href, if nil finds link placeholders ( elements with no href attribute)
Parameters:
-
locator
(String
) -- id, title, text, or alt of enclosed img element
Overloads:
-
find_link([locator], options={})
def find_link(locator = nil, **options, &optional_filter_block) find(:link, locator, options, &optional_filter_block) end
def first(*args, **options, &optional_filter_block)
-
(Capybara::ElementNotFound)
- If element(s) matching the provided options can't be found before time expires
Returns:
-
(Capybara::Node::Element)
- The found element or nil
Parameters:
-
options
(Hash
) -- Additional options; see {#all} -
locator
(String
) -- The selector -
kind
(:css, :xpath
) -- The type of selector
Overloads:
-
first([kind], locator, options)
def first(*args, **options, &optional_filter_block) options = { minimum: 1 }.merge(options) unless options_include_minimum?(options) all(*args, **options, &optional_filter_block).first end
def options_include_minimum?(opts)
def options_include_minimum?(opts) %i[count minimum between].any? { |k| opts.key?(k) } end
def prefer_exact?(query)
def prefer_exact?(query) query.match == :smart or query.match == :prefer_exact end
def sibling(*args, **options, &optional_filter_block)
-
(Capybara::ElementNotFound)
- If the element can't be found before time expires
Returns:
-
(Capybara::Node::Element)
- The found element
Options Hash:
(**options)
-
match
(Boolean
) -- The matching strategy to use.
Parameters:
-
(
) --
def sibling(*args, **options, &optional_filter_block) options[:session_options] = session_options synced_resolve Capybara::Queries::SiblingQuery.new(*args, **options, &optional_filter_block) end
def synced_resolve(query)
def synced_resolve(query) synchronize(query.wait) do if prefer_exact?(query) result = query.resolve_for(self, true) result = query.resolve_for(self, false) if result.empty? && query.supports_exact? && !query.exact? else result = query.resolve_for(self) end raise Capybara::Ambiguous, "Ambiguous match, found #{result.size} elements matching #{query.description}" if ambiguous?(query, result) raise Capybara::ElementNotFound, "Unable to find #{query.description}" if result.empty? result.first end.tap(&:allow_reload!) end