{"record":{"id":"86375c9de62cd5de","repo":"SeleniumHQ/selenium","slug":"you-may-only-deselect-all-options-of-a-multi-selec-86375c","errorCode":null,"errorMessage":"you may only deselect all options of a multi-select","messagePattern":"you may only deselect all options of a multi-select","errorType":"exception","errorClass":"Error::UnsupportedOperationError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/support/select.rb","lineNumber":156,"sourceCode":"        # Select all unselected options. Only valid if the element supports multiple selections.\n        #\n        # @raise [Error::UnsupportedOperationError] if the element does not support multiple selections.\n        #\n\n        def select_all\n          raise Error::UnsupportedOperationError, 'you may only select all options of a multi-select' unless multiple?\n\n          options.each { |e| select_option e }\n        end\n\n        #\n        # Deselect all selected options. Only valid if the element supports multiple selections.\n        #\n        # @raise [Error::UnsupportedOperationError] if the element does not support multiple selections.\n        #\n\n        def deselect_all\n          raise Error::UnsupportedOperationError, 'you may only deselect all options of a multi-select' unless multiple?\n\n          options.each { |e| deselect_option e }\n        end\n\n        private\n\n        def select_by_text(text)\n          opts = find_by_text text\n\n          return select_options(opts) unless opts.empty?\n\n          raise Error::NoSuchElementError, \"cannot locate element with text: #{text.inspect}\"\n        end\n\n        def select_by_index(index)\n          opts = find_by_index index\n\n          return select_option(opts.first) unless opts.empty?","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/support/select.rb#L138-L174","documentation":"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.","triggerScenarios":"Calling select.deselect_all when select.multiple? is false (the <select> lacks the 'multiple' attribute).","commonSituations":"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.","solutions":["Guard with select.multiple? before calling deselect_all.","Verify the <select> element has multiple attribute set.","For single-selects, switch selection with select_by rather than trying to clear it."],"exampleFix":"# before\nselect.deselect_all\n\n# after\nselect.deselect_all if select.multiple?","handlingStrategy":"validation","validationCode":"select.deselect_all if select.multiple?","typeGuard":"def multi_select?(select)\n  select.multiple?\nend","tryCatchPattern":"begin\n  select.deselect_all\nrescue Selenium::WebDriver::Error::UnsupportedOperationError\n  # single-select: nothing to deselect\nend","preventionTips":["Guard deselect_all with multiple?.","Verify the multiple attribute on the <select>.","For single-selects, switch selection via select_by instead of clearing."],"tags":["select","unsupported-operation","ruby"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}