{"record":{"id":"0eb356b4b8038f45","repo":"SeleniumHQ/selenium","slug":"no-options-are-selected-0eb356","errorCode":null,"errorMessage":"no options are selected","messagePattern":"no options are selected","errorType":"exception","errorClass":"Error::NoSuchElementError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/support/select.rb","lineNumber":78,"sourceCode":"        # @return [Array<Element>]\n        #\n\n        def selected_options\n          options.select(&:selected?)\n        end\n\n        #\n        # Get the first selected option in this select element\n        #\n        # @raise [Error::NoSuchElementError] if no options are selected\n        # @return [Element]\n        #\n\n        def first_selected_option\n          option = options.find(&:selected?)\n          return option if option\n\n          raise Error::NoSuchElementError, 'no options are selected'\n        end\n\n        #\n        # Select options by visible text, index or value.\n        #\n        # When selecting by :text, selects options that display text matching the argument. That is, when given \"Bar\" this\n        # would select an option like:\n        #\n        #     <option value=\"foo\">Bar</option>\n        #\n        # When selecting by :value, selects all options that have a value matching the argument. That is, when given \"foo\" this\n        # would select an option like:\n        #\n        #     <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        #","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/support/select.rb#L60-L96","documentation":"Support::Select#first_selected_option returns the first option whose selected? is true; if none is selected it raises Error::NoSuchElementError. This represents the W3C 'no selected option' state on the page rather than a code bug, so it surfaces as the standard WebDriver element-not-found error type.","triggerScenarios":"Calling select.first_selected_option on a <select> where zero <option> elements are selected (common for single-selects with no default selection, or after deselect_all on a multi-select).","commonSituations":"Asserting the default selection on a fresh single-select that has no pre-selected option; reading state after programmatic deselection; page load race where the select exists but options haven't been populated/selected yet.","solutions":["Check select.selected_options.any? (or select.selected_options.empty?) before calling first_selected_option.","Confirm the select actually has a default selected <option> in the HTML (an option with the 'selected' attribute).","Handle the NoSuchElementError as the expected 'nothing selected' case in your assertion."],"exampleFix":"# before\nchosen = select.first_selected_option\n\n# after\nif select.selected_options.empty?\n  chosen = nil\nelse\n  chosen = select.first_selected_option\nend","handlingStrategy":"validation","validationCode":"if select.selected_options.empty?\n  chosen = nil\nelse\n  chosen = select.first_selected_option\nend","typeGuard":"def has_selected_option?(select)\n  select.selected_options.any?\nend","tryCatchPattern":"begin\n  select.first_selected_option\nrescue Selenium::WebDriver::Error::NoSuchElementError\n  # no option selected — handle accordingly\n  nil\nend","preventionTips":["Check selected_options.any? before calling first_selected_option.","Confirm the <select> has a default-selected <option> in markup.","Treat NoSuchElementError here as expected 'nothing selected' state."],"tags":["select","no-such-element","state-check","ruby"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}