Method: Capybara::Node::Actions#choose

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

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

Find a descendant radio button and mark it as checked. The radio button 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 choose a descendant radio button with a name, id, or label text matching 'Male'
page.choose('Male')

# will choose `el` if it's a radio button element
el.choose()

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 radio button to choose

Options Hash (**options):

  • option (String)

    Value of the radio_button to choose

  • 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

  • wait (false, true, Numeric)

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

  • allow_label_click (Boolean)

    Attempt to click the label to toggle state if element is non-visible. Defaults to automatic_label_click.

Returns:


121
122
123
# File 'lib/capybara/node/actions.rb', line 121

def choose(locator = nil, **options)
  _check_with_label(:radio_button, true, locator, **options)
end