SeleniumHQ/selenium · error · Error::UnsupportedOperationError

you may only deselect all options of a multi-select

Error message

you may only deselect all options of a multi-select

What it means

Support::Select#deselect_all clears every selected option, an operation only valid on <select multiple>. On a single-select there is nothing to deselect (the browser keeps one option selected), so the binding raises Error::UnsupportedOperationError upfront.

Source

Thrown at rb/lib/selenium/webdriver/support/select.rb:156

        # Select all unselected options. Only valid if the element supports multiple selections.
        #
        # @raise [Error::UnsupportedOperationError] if the element does not support multiple selections.
        #

        def select_all
          raise Error::UnsupportedOperationError, 'you may only select all options of a multi-select' unless multiple?

          options.each { |e| select_option e }
        end

        #
        # Deselect all selected options. Only valid if the element supports multiple selections.
        #
        # @raise [Error::UnsupportedOperationError] if the element does not support multiple selections.
        #

        def deselect_all
          raise Error::UnsupportedOperationError, 'you may only deselect all options of a multi-select' unless multiple?

          options.each { |e| deselect_option e }
        end

        private

        def select_by_text(text)
          opts = find_by_text text

          return select_options(opts) unless opts.empty?

          raise Error::NoSuchElementError, "cannot locate element with text: #{text.inspect}"
        end

        def select_by_index(index)
          opts = find_by_index index

          return select_option(opts.first) unless opts.empty?

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Guard with select.multiple? before calling deselect_all.
  2. Verify the <select> element has multiple attribute set.
  3. For single-selects, switch selection with select_by rather than trying to clear it.

Example fix

# before
select.deselect_all

# after
select.deselect_all if select.multiple?
Defensive patterns

Strategy: validation

Validate before calling

select.deselect_all if select.multiple?

Type guard

def multi_select?(select)
  select.multiple?
end

Try / catch

begin
  select.deselect_all
rescue Selenium::WebDriver::Error::UnsupportedOperationError
  # single-select: nothing to deselect
end

Prevention

When it happens

Trigger: Calling select.deselect_all when select.multiple? is false (the <select> lacks the 'multiple' attribute).

Common situations: A teardown/cleanup routine calling deselect_all on every select on the page without checking type; page markup changed from multi to single select; wrong element matched by the locator.

Related errors


AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14). Data as JSON: /api/errors/86375c9de62cd5de. Report an issue: GitHub.