{"record":{"id":"7de434cc0cec5c4e","repo":"SeleniumHQ/selenium","slug":"you-may-only-deselect-option-of-a-multi-select","errorCode":null,"errorMessage":"you may only deselect option of a multi-select","messagePattern":"you may only deselect option of a multi-select","errorType":"exception","errorClass":"Error::UnsupportedOperationError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/support/select.rb","lineNumber":188,"sourceCode":"\n        def select_by_index(index)\n          opts = find_by_index index\n\n          return select_option(opts.first) unless opts.empty?\n\n          raise Error::NoSuchElementError, \"cannot locate element with index: #{index.inspect}\"\n        end\n\n        def select_by_value(value)\n          opts = find_by_value value\n\n          return select_options(opts) unless opts.empty?\n\n          raise Error::NoSuchElementError, \"cannot locate option with value: #{value.inspect}\"\n        end\n\n        def deselect_by_text(text)\n          raise Error::UnsupportedOperationError, 'you may only deselect option of a multi-select' unless multiple?\n\n          opts = find_by_text text\n\n          return deselect_options(opts) unless opts.empty?\n\n          raise Error::NoSuchElementError, \"cannot locate element with text: #{text.inspect}\"\n        end\n\n        def deselect_by_value(value)\n          raise Error::UnsupportedOperationError, 'you may only deselect option of a multi-select' unless multiple?\n\n          opts = find_by_value value\n\n          return deselect_options(opts) unless opts.empty?\n\n          raise Error::NoSuchElementError, \"cannot locate option with value: #{value.inspect}\"\n        end\n","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/support/select.rb#L170-L206","documentation":"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.","triggerScenarios":"Calling select.deselect_by(:text, 'Bar') on a single-select (select.multiple? == false), regardless of whether 'Bar' exists.","commonSituations":"Generic deselect helper that runs against all selects on the page; markup changed from multi to single; wrong element matched by locator.","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."],"exampleFix":"# before\nselect.deselect_by(:text, 'Bar')\n\n# after\nselect.deselect_by(:text, 'Bar') if select.multiple?","handlingStrategy":"validation","validationCode":"select.deselect_by(:text, text) if select.multiple?","typeGuard":"def multi_select?(select)\n  select.multiple?\nend","tryCatchPattern":"begin\n  select.deselect_by(:text, text)\nrescue Selenium::WebDriver::Error::UnsupportedOperationError\n  # single-select: cannot deselect, skip\nend","preventionTips":["Guard deselect_by with multiple?.","Confirm the multiple attribute on the <select>.","Use select_by to change selection on single-selects."],"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"}