module Capybara::Node::Finders

def all(*args, allow_reload: false, **options, &optional_filter_block)

Raises:
  • (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)
  • allow_reload (Boolean) -- Beta feature - May be removed in any version.
  • 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

Parameters:
  • locator (String) -- The locator for the specified selector
  • kind (Symbol) -- Optional selector type (:css, :xpath, :field, etc.). Defaults to {Capybara.configure default_selector}.
def all(*args, allow_reload: false, **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, **options, &optional_filter_block)
  result = nil
  begin
    synchronize(query.wait) do
      result = query.resolve_for(self)
      result.allow_reload! if allow_reload
      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)
  %i[one smart].include?(query.match) && (result.size > 1)
end

def ancestor(*args, **options, &optional_filter_block)

Raises:
  • (Capybara::ElementNotFound) - If the element can't be found before time expires

Returns:
  • (Capybara::Node::Element) - The found element

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)

Raises:
  • (Capybara::ElementNotFound) - If the element can't be found before time expires

Returns:
  • (Capybara::Node::Element) - The found element

Options Hash: (**options)
  • match (Symbol) -- The matching strategy to use. Defaults to {Capybara.configure match}.
  • exact (Boolean) -- Control whether `is` expressions in the given XPath match exactly or partially. Defaults to {Capybara.configure exact}.
  • style (String, Regexp, Hash) -- Only find elements with matching style. String and Regexp will be checked against text of the elements `style` attribute, while a Hash will be compared against the elements full style
  • class (String, Array, Regexp) -- Only find elements with matching class/classes.
  • id (String, Regexp) -- Only find elements with an id that matches the value passed
  • obscured (Boolean) -- Only find elements with the specified obscured state:
  • visible (Boolean, Symbol) --
  • normalize_ws (Boolean) --
  • exact_text (String, Regexp, String) --
  • text (String, Regexp) -- Only find elements which contain this text or match this regexp

Parameters:
  • () --
def find(*args, **options, &optional_filter_block)
  options[:session_options] = session_options
  count_options = options.slice(*Capybara::Queries::BaseQuery::COUNT_KEYS)
  unless count_options.empty?
    Capybara::Helpers.warn(
      "'find' does not support count options (#{count_options}) ignoring. " \
      "Called from: #{Capybara::Helpers.filter_backtrace(caller)}"
    )
  end
  synced_resolve Capybara::Queries::SelectorQuery.new(*args, **options, &optional_filter_block)
end

def find_button(locator = nil, **options, &optional_filter_block)

Returns:
  • (Capybara::Node::Element) - The found element

Options Hash: (**options)
  • class (String, Array, Regexp) -- Match buttons that match the class(es) provided
  • value (String) -- Match buttons with the value provided
  • title (String) -- Match buttons with the title provided
  • name (String) -- Match buttons with the name provided
  • id (String, Regexp) -- Match buttons with the id provided
  • disabled (Boolean, Symbol) -- Match disabled button?

Parameters:
  • locator (String) -- id, name, {Capybara.configure test_id} attribute, value, title, text content, alt of image

Overloads:
  • find_button([locator], **options)
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)

Returns:
  • (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)

Returns:
  • (Capybara::Node::Element) - The found element

Options Hash: (**options)
  • class (String, Array, Regexp) -- Match fields that match the class(es) passed
  • placeholder (String) -- Match fields that match the placeholder attribute
  • name (String) -- Match fields that match the name attribute
  • id (String, Regexp) -- Match fields that match the id attribute
  • multiple (Boolean) -- Match fields that can have multiple values?
  • type (String) -- Type of field to match on
  • with (String, Regexp) -- Value of field to match on
  • readonly (Boolean) -- Match readonly field?
  • disabled (Boolean, Symbol) -- Match disabled field?
  • unchecked (Boolean) -- Match unchecked field?
  • checked (Boolean) -- Match checked field?

Parameters:
  • locator (String) -- name, id, {Capybara.configure test_id} attribute, placeholder or text of associated label element

Overloads:
  • find_field([locator], **options)
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)

Returns:
  • (Capybara::Node::Element) - The found element

Options Hash: (**options)
  • class (String, Array, Regexp) -- Match links that match the class(es) provided
  • target (String) -- Match links with the target provided
  • download (String, Boolean) -- Match links with the download provided
  • alt (String) -- Match links with a contained img element whose alt matches
  • title (String) -- Match links with the title provided
  • id (String, Regexp) -- 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), if `false` ignores the href

Parameters:
  • locator (String) -- id, {Capybara.configure test_id} attribute, 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)

Raises:
  • (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 (Symbol) -- 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? { |key| opts.key?(key) }
end

def parent

def parent
  first(:xpath, './parent::*', minimum: 0)
end

def prefer_exact?(query)

def prefer_exact?(query)
  %i[smart prefer_exact].include?(query.match)
end

def sibling(*args, **options, &optional_filter_block)

Raises:
  • (Capybara::ElementNotFound) - If the element can't be found before time expires

Returns:
  • (Capybara::Node::Element) - The found element

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
    if ambiguous?(query, result)
      raise Capybara::Ambiguous, "Ambiguous match, found #{result.size} elements matching #{query.applied_description}"
    end
    raise Capybara::ElementNotFound, "Unable to find #{query.applied_description}" if result.empty?
    result.first
  end.tap(&:allow_reload!)
end