{"record":{"id":"039bc9c0b5bb6f5f","repo":"SeleniumHQ/selenium","slug":"can-t-select-options-by-how-inspect","errorCode":null,"errorMessage":"can't select options by #{how.inspect}","messagePattern":"can't select options by #(.+?)","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/support/select.rb","lineNumber":110,"sourceCode":"        #     <option value=\"foo\">Bar</option>\n        #\n        # When selecting by :index, selects the option at the given index. This is done by examining the \"index\" attribute of an\n        # element, and not merely by counting.\n        #\n        # @param [:text, :index, :value] how How to find the option\n        # @param [String] what What value to find the option by.\n        #\n\n        def select_by(how, what)\n          case how\n          when :text\n            select_by_text what\n          when :index\n            select_by_index what\n          when :value\n            select_by_value what\n          else\n            raise ArgumentError, \"can't select options by #{how.inspect}\"\n          end\n        end\n\n        #\n        # 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","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/support/select.rb#L92-L128","documentation":"Support::Select#select_by switches on the how argument and accepts only :text, :index, or :value. Any other Symbol/value falls to else and raises ArgumentError. This is a misuse of the API surface rather than a page-state problem.","triggerScenarios":"Calling select.select_by(:id, 'x'), select.select_by('text', 'x') (String instead of Symbol — 'text' != :text), select.select_by(:name, 'x'), or passing any key not in {text, index, value}.","commonSituations":"Using a find-strategy Symbol from driver.find_element (e.g. :id, :css, :name) that is invalid for Select; passing a String 'text' instead of the Symbol :text; copy-pasting a different library's locator API.","solutions":["Use one of the three valid selectors: select.select_by(:text, 'Bar'), select.select_by(:value, 'foo'), or select.select_by(:index, 0).","Pass Symbols not Strings for how.","If you need css/xpath/id selection, find the option element directly and click it instead of using select_by."],"exampleFix":"# before\nselect.select_by('text', 'Bar')\n\n# after\nselect.select_by(:text, 'Bar')","handlingStrategy":"validation","validationCode":"VALID_HOW = %i[text index value].freeze\nraise ArgumentError, \"bad how #{how}\" unless VALID_HOW.include?(how)\nselect.select_by(how, what)","typeGuard":"def valid_select_how?(how)\n  %i[text index value].include?(how)\nend","tryCatchPattern":"begin\n  select.select_by(how, what)\nrescue ArgumentError => e\n  raise unless e.message.include?(\"can't select options\")\n  select.select_by(:text, what.to_s)\nend","preventionTips":["Pass Symbols (:text, :index, :value) — not Strings.","Do not reuse driver.find_element locator symbols for select_by.","Wrap select_by in a helper that validates how against the allowed set."],"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"}