SeleniumHQ/selenium · error · Error::UnsupportedOperationError
you may only deselect option of a multi-select
Error message
you may only deselect option of a multi-select
What it means
Private deselect_by_text first checks multiple? and raises Error::UnsupportedOperationError if the select is not a multi-select. Deselection is only meaningful on <select multiple>; on a single-select you cannot clear a selection, so the operation is rejected before lookup. This guard runs before the text search, so it fires even if the text exists.
Source
Thrown at rb/lib/selenium/webdriver/support/select.rb:188
def select_by_index(index)
opts = find_by_index index
return select_option(opts.first) unless opts.empty?
raise Error::NoSuchElementError, "cannot locate element with index: #{index.inspect}"
end
def select_by_value(value)
opts = find_by_value value
return select_options(opts) unless opts.empty?
raise Error::NoSuchElementError, "cannot locate option with value: #{value.inspect}"
end
def deselect_by_text(text)
raise Error::UnsupportedOperationError, 'you may only deselect option of a multi-select' unless multiple?
opts = find_by_text text
return deselect_options(opts) unless opts.empty?
raise Error::NoSuchElementError, "cannot locate element with text: #{text.inspect}"
end
def deselect_by_value(value)
raise Error::UnsupportedOperationError, 'you may only deselect option of a multi-select' unless multiple?
opts = find_by_value value
return deselect_options(opts) unless opts.empty?
raise Error::NoSuchElementError, "cannot locate option with value: #{value.inspect}"
end
View on GitHub (pinned to aa36b38e69)
Solutions
- Guard with select.multiple? before calling deselect_by(:text, ...).
- Confirm the <select> has the multiple attribute.
- For single-selects, change selection with select_by instead of deselecting.
Example fix
# before select.deselect_by(:text, 'Bar') # after select.deselect_by(:text, 'Bar') if select.multiple?
Defensive patterns
Strategy: validation
Validate before calling
select.deselect_by(:text, text) if select.multiple?
Type guard
def multi_select?(select) select.multiple? end
Try / catch
begin select.deselect_by(:text, text) rescue Selenium::WebDriver::Error::UnsupportedOperationError # single-select: cannot deselect, skip end
Prevention
- Guard deselect_by with multiple?.
- Confirm the multiple attribute on the <select>.
- Use select_by to change selection on single-selects.
When it happens
Trigger: Calling select.deselect_by(:text, 'Bar') on a single-select (select.multiple? == false), regardless of whether 'Bar' exists.
Common situations: Generic deselect helper that runs against all selects on the page; markup changed from multi to single; wrong element matched by locator.
Related errors
- you may only select all options of a multi-select
- you may only deselect all options of a multi-select
- Full Page Screenshots are not supported for #{inspect}
- unexpected tag name #{tag_name.inspect}
- no options are selected
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/7de434cc0cec5c4e.
Report an issue: GitHub.