Method: Capybara::Node::Matchers#has_css?

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

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

Checks if a given CSS selector is on the page or a descendant of the current node.

page.has_css?('p#foo')

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

page.has_css?('p#foo', count: 4)

This will check if the selector occurs exactly 4 times.

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

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

Parameters:

  • path (String)

    A CSS selector

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :count (Integer) — default: nil

    Number of times the selector should occur

Returns:

  • (Boolean)

    If the selector exists


309
310
311
# File 'lib/capybara/node/matchers.rb', line 309

def has_css?(path, **options, &optional_filter_block)
  has_selector?(:css, path, **options, &optional_filter_block)
end