Method: Capybara::Node::Matchers#has_xpath?

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

#has_xpath?(path, **options, &optional_filter_block) ⇒ Boolean

Checks if a given XPath expression is on the page or a descendant of the current node.

page.has_xpath?('.//p[@id="foo"]')

By default it will check if the expression occurs at least once, but a different number can be specified.

page.has_xpath?('.//p[@id="foo"]', count: 4)

This will check if the expression occurs exactly 4 times.

It also accepts all options that Finders#all accepts, such as :text and :visible.

page.has_xpath?('.//li', text: 'Horse', visible: true)

#has_xpath? can also accept XPath expressions generated by the XPath gem:

xpath = XPath.generate { |x| x.descendant(:p) }
page.has_xpath?(xpath)

Parameters:

  • path (String)

    An XPath expression

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :count (Integer) — default: nil

    Number of times the expression should occur

Returns:

  • (Boolean)

    If the expression exists



270
271
272
# File 'lib/capybara/node/matchers.rb', line 270

def has_xpath?(path, **options, &optional_filter_block)
  has_selector?(:xpath, path, **options, &optional_filter_block)
end