Method: Capybara::Node::Actions#check

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

#check([locator], **options) ⇒ Capybara::Node::Element

Find a descendant check box and mark it as checked. The check box can be found via name, id, test_id attribute, or label text. If no locator is provided this will match against self or a descendant.

# will check a descendant checkbox with a name, id, or label text matching 'German'
page.check('German')

# will check `el` if it's a checkbox element
el.check()

If the driver is capable of executing JavaScript, this method will wait for a set amount of time and continuously retry finding the element until either the element is found or the time expires. The length of time this method will wait is controlled through default_max_wait_time.

Parameters:

  • locator (String)

    Which check box to check

Options Hash (**options):

  • option (String)

    Value of the checkbox to select

  • id (String, Regexp)

    Match fields that match the id attribute

  • name (String)

    Match fields that match the name attribute

  • class (String, Array<String>, Regexp)

    Match fields that match the class(es) provided

  • allow_label_click (Boolean, Hash)

    Attempt to click the label to toggle state if element is non-visible. Defaults to automatic_label_click. If set to a Hash it is passed as options to the click on the label

  • wait (false, true, Numeric)

    Maximum time to wait for matching element to appear. Defaults to default_max_wait_time.

Returns:



150
151
152
# File 'lib/capybara/node/actions.rb', line 150

def check(locator = nil, **options)
  _check_with_label(:checkbox, true, locator, **options)
end