{"record":{"id":"00cd9cc46d25224d","repo":"SeleniumHQ/selenium","slug":"you-may-only-deselect-all-options-of-a-multi-selec-00cd9c","errorCode":null,"errorMessage":"You may only deselect all options of a multi-select","messagePattern":"You may only deselect all options of a multi-select","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/support/select.py","lineNumber":155,"sourceCode":"                    if not self._has_css_property_and_visible(candidate):\n                        raise NoSuchElementException(f\"Invisible option with text: {text}\")\n                    self._set_selected(candidate)\n                    if not self.is_multiple:\n                        return\n                    matched = True\n\n        if not matched:\n            raise NoSuchElementException(f\"Could not locate element with visible text: {text}\")\n\n    def deselect_all(self) -> None:\n        \"\"\"Clear all selected entries.\n\n        This is only valid when the SELECT supports multiple selections.\n        throws NotImplementedError If the SELECT does not support\n        multiple selections\n        \"\"\"\n        if not self.is_multiple:\n            raise NotImplementedError(\"You may only deselect all options of a multi-select\")\n        for opt in self.options:\n            self._unset_selected(opt)\n\n    def deselect_by_value(self, value: str) -> None:\n        \"\"\"Deselect all options that have a value matching the argument.\n\n        Example:\n            When given \"foo\" this would deselect 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        if not self.is_multiple:","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/support/select.py#L137-L173","documentation":"`deselect_all()` clears every option, but only multi-selects support multiple selections. On a single-select it raises `NotImplementedError` because deselect-all is undefined for non-multiple selects (a single select always has exactly one chosen option).","triggerScenarios":"Calling `select.deselect_all()` on a `<select>` without the `multiple` attribute (`is_multiple` is False). The guard `if not self.is_multiple:` fires immediately.","commonSituations":"Generic helper code that assumes all selects are multi-select; a select that lost its `multiple` attribute after a page change; test reuse across different form types.","solutions":["Check `select.is_multiple` before calling: `if select.is_multiple: select.deselect_all()`","For a single-select, 'clear' by selecting a different/blank option instead","Catch NotImplementedError to handle single-selects gracefully"],"exampleFix":"// before\nselect.deselect_all()\n\n// after\nif select.is_multiple:\n    select.deselect_all()\nelse:\n    select.select_by_index(0)  # reset to default","handlingStrategy":"validation","validationCode":"if select.is_multiple:\n    select.deselect_all()","typeGuard":"def is_multi(select_obj) -> bool:\n    return bool(select_obj.is_multiple)","tryCatchPattern":null,"preventionTips":["Check select.is_multiple before deselect_all","For single-selects, reset by selecting the default option","Branch generic helpers on is_multiple"],"tags":["select","multi-select","selenium-python"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}