{"record":{"id":"803eb71195e11086","repo":"SeleniumHQ/selenium","slug":"you-may-only-deselect-options-of-a-multi-select-803eb7","errorCode":null,"errorMessage":"You may only deselect options of a multi-select","messagePattern":"You may only deselect options of a multi-select","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/support/select.py","lineNumber":174,"sourceCode":"        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:\n            raise NotImplementedError(\"You may only deselect options of a multi-select\")\n        matched = False\n        css = f\"option[value = {self._escape_string(value)}]\"\n        opts = self._el.find_elements(By.CSS_SELECTOR, css)\n        for opt in opts:\n            self._unset_selected(opt)\n            matched = True\n        if not matched:\n            raise NoSuchElementException(f\"Could not locate element with value: {value}\")\n\n    def deselect_by_index(self, index: int) -> None:\n        \"\"\"Deselect the option at the given index by examining the \"index\" attribute.\n\n        Args:\n            index: The option at this index will be deselected\n\n        Raises:\n            NoSuchElementException: If there is no option with specified index in SELECT\n        \"\"\"","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/support/select.py#L156-L192","documentation":"`deselect_by_value()` only operates on multi-selects. On a single-select it raises `NotImplementedError('You may only deselect options of a multi-select')` before doing any work, because deselect semantics are invalid for single-select elements.","triggerScenarios":"Calling `select.deselect_by_value('foo')` when the wrapped select lacks `multiple` (so `is_multiple` is False). The very first guard raises.","commonSituations":"Shared utility code run against heterogeneous selects; assuming a select is multiple when it is not; form schema changed and a formerly-multi select became single.","solutions":["Guard with `if select.is_multiple:` before calling","For single-selects, change selection rather than deselect","Catch NotImplementedError to branch on select type"],"exampleFix":"// before\nselect.deselect_by_value(\"foo\")\n\n// after\nif select.is_multiple:\n    select.deselect_by_value(\"foo\")","handlingStrategy":"validation","validationCode":"if select.is_multiple:\n    select.deselect_by_value(value)","typeGuard":"def is_multi(select_obj) -> bool:\n    return bool(select_obj.is_multiple)","tryCatchPattern":null,"preventionTips":["Guard all deselect_* calls with select.is_multiple","Treat single-selects separately in shared utilities","Reset single-selects by selecting another option, not deselecting"],"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"}