{"record":{"id":"e3bc4e53b930175b","repo":"SeleniumHQ/selenium","slug":"you-may-not-select-a-disabled-option","errorCode":null,"errorMessage":"You may not select a disabled option","messagePattern":"You may not select a disabled option","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/support/select.py","lineNumber":228,"sourceCode":"            text: The visible text to match against\n        \"\"\"\n        if not self.is_multiple:\n            raise NotImplementedError(\"You may only deselect options of a multi-select\")\n        matched = False\n        xpath = f\".//option[normalize-space(.) = {self._escape_string(text)}]\"\n        opts = self._el.find_elements(By.XPATH, xpath)\n        for opt in opts:\n            if not self._has_css_property_and_visible(opt):\n                raise NoSuchElementException(f\"Invisible option with text: {text}\")\n            self._unset_selected(opt)\n            matched = True\n        if not matched:\n            raise NoSuchElementException(f\"Could not locate element with visible text: {text}\")\n\n    def _set_selected(self, option) -> None:\n        if not option.is_selected():\n            if not option.is_enabled():\n                raise NotImplementedError(\"You may not select a disabled option\")\n            option.click()\n\n    def _unset_selected(self, option) -> None:\n        if option.is_selected():\n            option.click()\n\n    def _escape_string(self, value: str) -> str:\n        if '\"' in value and \"'\" in value:\n            substrings = value.split('\"')\n            result = [\"concat(\"]\n            for substring in substrings:\n                result.append(f'\"{substring}\"')\n                result.append(\", '\\\"', \")\n            result = result[0:-1]\n            if value.endswith('\"'):\n                result.append(\", '\\\"'\")\n            return \"\".join(result) + \")\"\n","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/support/select.py#L210-L246","documentation":"The internal `_set_selected()` helper clicks an option to select it, but only if the option is enabled. If `option.is_enabled()` is False it raises `NotImplementedError('You may not select a disabled option')`, surfacing a disabled-option attempt from any of the select_by_* methods.","triggerScenarios":"Any select method (`select_by_value/index/visible_text`) targeting an `<option disabled>` that is not already selected. `_set_selected` sees the option isn't selected and isn't enabled, so it raises before clicking.","commonSituations":"Selecting a disabled/placeholder option; the option becomes disabled under certain conditions (form state); test data points at an option the UI intentionally disables; race where an option is disabled between location and click.","solutions":["Filter to enabled options before selecting: ensure `option.is_enabled()`","Choose a different, enabled option matching your intent","Remove the disabled attribute via JS only if testing requires it: `driver.execute_script('arguments[0].removeAttribute(\"disabled\")', opt)`","Catch NotImplementedError and pick an alternate option"],"exampleFix":"// before\nselect.select_by_value(\"disabled_opt\")\n\n// after\nopt = next((o for o in select.options if o.get_attribute(\"value\") == \"enabled_opt\"), None)\nif opt and opt.is_enabled():\n    select.select_by_value(\"enabled_opt\")","handlingStrategy":"validation","validationCode":"opt = next((o for o in select.options if o.get_attribute(\"value\") == value), None)\nif opt and opt.is_enabled():\n    select.select_by_value(value)","typeGuard":"def option_enabled(select_obj, value) -> bool:\n    for o in select_obj.options:\n        if o.get_attribute(\"value\") == value:\n            return o.is_enabled()\n    return False","tryCatchPattern":"try:\n    select.select_by_value(value)\nexcept NotImplementedError:\n    # option is disabled — choose an enabled alternative\n    pass","preventionTips":["Check option.is_enabled() before selecting","Avoid selecting placeholder/disabled options","Remove disabled via JS only when the test specifically requires overriding UI state"],"tags":["select","disabled-element","selenium-python"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}