Method: Capybara::Node::Matchers#has_select?

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

#has_select?(locator = nil, **options, &optional_filter_block) ⇒ Boolean

Checks if the page or current node has a select field with the given label, name or id.

It can be specified which option should currently be selected:

page.has_select?('Language', selected: 'German')

For multiple select boxes, several options may be specified:

page.has_select?('Language', selected: ['English', 'German'])

It's also possible to check if the exact set of options exists for this select box:

page.has_select?('Language', options: ['English', 'German', 'Spanish'])

You can also check for a partial set of options:

page.has_select?('Language', with_options: ['English', 'German'])

Parameters:

  • locator (String) (defaults to: nil)

    The label, name or id of a select box

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :options (Array)

    Options which should be contained in this select box

  • :with_options (Array)

    Partial set of options which should be contained in this select box

  • :selected (String, Array)

    Options which should be selected

  • :with_selected (String, Array)

    Partial set of options which should minimally be selected

Returns:

  • (Boolean)

    Whether it exists



520
521
522
# File 'lib/capybara/node/matchers.rb', line 520

def has_select?(locator = nil, **options, &optional_filter_block)
  has_selector?(:select, locator, **options, &optional_filter_block)
end