{"record":{"id":"ad54c78436ce3b06","repo":"SeleniumHQ/selenium","slug":"can-t-deselect-options-by-how-inspect","errorCode":null,"errorMessage":"can't deselect options by #{how.inspect}","messagePattern":"can't deselect options by #(.+?)","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/support/select.rb","lineNumber":133,"sourceCode":"        # Deselect options by visible text, index or value.\n        #\n        # @param [:text, :index, :value] how How to find the option\n        # @param [String] what What value to find the option by.\n        # @raise [Error::UnsupportedOperationError] if the element does not support multiple selections.\n        #\n        # @see Select#select_by\n        #\n\n        def deselect_by(how, what)\n          case how\n          when :text\n            deselect_by_text what\n          when :value\n            deselect_by_value what\n          when :index\n            deselect_by_index what\n          else\n            raise ArgumentError, \"can't deselect options by #{how.inspect}\"\n          end\n        end\n\n        #\n        # 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        #","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/support/select.rb#L115-L151","documentation":"Support::Select#deselect_by mirrors select_by: it switches on how and accepts only :text, :value, :index. Any other value raises ArgumentError. Like 487 this is an API-misuse error, distinct from the UnsupportedOperationError raised when deselect is attempted on a single-select.","triggerScenarios":"Calling select.deselect_by(:id, 'x'), select.deselect_by(:name, 'x'), select.deselect_by('value', 'x') (String key), or any how outside {text, value, index}.","commonSituations":"Reusing locator symbols from elsewhere in the test (css, id, name); passing a String instead of Symbol; assuming deselect supports the same locator types as driver.find_element.","solutions":["Use one of :text, :value, or :index for how.","Pass a Symbol, not a String.","For other locator strategies, find and click the option element directly to toggle it."],"exampleFix":"# before\nselect.deselect_by('value', 'foo')\n\n# after\nselect.deselect_by(:value, 'foo')","handlingStrategy":"validation","validationCode":"VALID_HOW = %i[text value index].freeze\nraise ArgumentError, \"bad how #{how}\" unless VALID_HOW.include?(how)\nselect.deselect_by(how, what)","typeGuard":"def valid_deselect_how?(how)\n  %i[text value index].include?(how)\nend","tryCatchPattern":"begin\n  select.deselect_by(how, what)\nrescue ArgumentError => e\n  raise unless e.message.include?(\"can't deselect options\")\n  select.deselect_by(:value, what.to_s)\nend","preventionTips":["Pass Symbols, not Strings, for how.","Restrict how to {text, value, index}.","Validate how in a shared helper to fail fast with a clear message."],"tags":["select","argument-error","ruby"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}