{"record":{"id":"d6849afccb63681c","repo":"SeleniumHQ/selenium","slug":"no-options-are-selected","errorCode":null,"errorMessage":"No options are selected","messagePattern":"No options are selected","errorType":"exception","errorClass":"NoSuchElementException","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/support/select.py","lineNumber":60,"sourceCode":"        self.is_multiple = multi and multi != \"false\"\n\n    @property\n    def options(self) -> list[WebElement]:\n        \"\"\"Returns a list of all options belonging to this select tag.\"\"\"\n        return self._el.find_elements(By.TAG_NAME, \"option\")\n\n    @property\n    def all_selected_options(self) -> list[WebElement]:\n        \"\"\"Return a list of all selected options belonging to this select tag.\"\"\"\n        return [opt for opt in self.options if opt.is_selected()]\n\n    @property\n    def first_selected_option(self) -> WebElement:\n        \"\"\"Return the first selected option or the currently selected option.\"\"\"\n        for opt in self.options:\n            if opt.is_selected():\n                return opt\n        raise NoSuchElementException(\"No options are selected\")\n\n    def select_by_value(self, value: str) -> None:\n        \"\"\"Select all options that have a value matching the argument.\n\n        Example:\n            When given \"foo\" this would select an option like:\n\n                `<option value=\"foo\">Bar</option>`\n\n        Args:\n            value: The value to match against\n\n        Raises:\n            NoSuchElementException: If there is no option with specified value in SELECT\n        \"\"\"\n        css = f\"option[value ={self._escape_string(value)}]\"\n        opts = self._el.find_elements(By.CSS_SELECTOR, css)\n        matched = False","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/support/select.py#L42-L78","documentation":"The `first_selected_option` property iterates the select's options and returns the first selected one. If none are selected it raises `NoSuchElementException`, since the caller asked for a selection that does not exist.","triggerScenarios":"Reading `Select(el).first_selected_option` on a single-select whose default option is deselected, or a multi-select with nothing chosen. Also right after a `deselect_all()` before any new selection.","commonSituations":"Asserting the default selection on a page where the select starts empty; reading state immediately after clearing; race condition where the page reset the selection before the read.","solutions":["Guard with `all_selected_options` first: `if select.all_selected_options: opt = select.first_selected_option`","Catch NoSuchElementException and treat it as 'nothing selected' in your assertion flow","If you expect a default, select one explicitly before reading"],"exampleFix":"// before\nopt = select.first_selected_option\n\n// after\nselected = select.all_selected_options\nopt = selected[0] if selected else None","handlingStrategy":"try-catch","validationCode":"if select.all_selected_options:\n    opt = select.first_selected_option\nelse:\n    opt = None","typeGuard":"def has_selected(select_obj) -> bool:\n    return len(select_obj.all_selected_options) > 0","tryCatchPattern":"from selenium.common.exceptions import NoSuchElementException\n\ntry:\n    opt = select.first_selected_option\nexcept NoSuchElementException:\n    opt = None  # nothing selected","preventionTips":["Prefer reading all_selected_options when empty-state is valid","After deselect_all, expect first_selected_option to raise","Treat NoSuchElementException here as application state, not a failure"],"tags":["select","state","selenium-python"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}