Method: Capybara::Node::Actions#unselect

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

#unselect(value = nil, from: nil, **options) ⇒ Capybara::Node::Element

Find a select box on the page and unselect a particular option from it. If the select box is a multiple select, #unselect can be called multiple times to unselect more than one option. The select box can be found via its name, id, test_id attribute, or label text.

page.unselect 'March', from: 'Month'

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:

  • value (String) (defaults to: nil)

    Which option to unselect

  • from (String) (defaults to: nil)

    The id, test_id attribute, name or label of the select box

Options Hash (**options):

  • wait (false, true, Numeric)

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

Returns:

Raises:

  • (ArgumentError)


230
231
232
233
234
235
# File 'lib/capybara/node/actions.rb', line 230

def unselect(value = nil, from: nil, **options)
  raise ArgumentError, 'The :from option does not take an element' if from.is_a? Capybara::Node::Element

  scope = from ? find(:select, from, **options) : self
  scope.find(:option, value, **options).unselect_option
end