SeleniumHQ/selenium · error · NotImplementedError
You may only deselect options of a multi-select
Error message
You may only deselect options of a multi-select
What it means
`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.
Source
Thrown at py/selenium/webdriver/support/select.py:174
for opt in self.options:
self._unset_selected(opt)
def deselect_by_value(self, value: str) -> None:
"""Deselect all options that have a value matching the argument.
Example:
When given "foo" this would deselect an option like:
`<option value="foo">Bar</option>`
Args:
value: The value to match against
Raises:
NoSuchElementException: If there is no option with specified value in SELECT
"""
if not self.is_multiple:
raise NotImplementedError("You may only deselect options of a multi-select")
matched = False
css = f"option[value = {self._escape_string(value)}]"
opts = self._el.find_elements(By.CSS_SELECTOR, css)
for opt in opts:
self._unset_selected(opt)
matched = True
if not matched:
raise NoSuchElementException(f"Could not locate element with value: {value}")
def deselect_by_index(self, index: int) -> None:
"""Deselect the option at the given index by examining the "index" attribute.
Args:
index: The option at this index will be deselected
Raises:
NoSuchElementException: If there is no option with specified index in SELECT
"""View on GitHub (pinned to aa36b38e69)
Solutions
- Guard with `if select.is_multiple:` before calling
- For single-selects, change selection rather than deselect
- Catch NotImplementedError to branch on select type
Example fix
// before
select.deselect_by_value("foo")
// after
if select.is_multiple:
select.deselect_by_value("foo") Defensive patterns
Strategy: validation
Validate before calling
if select.is_multiple:
select.deselect_by_value(value) Type guard
def is_multi(select_obj) -> bool:
return bool(select_obj.is_multiple) Prevention
- Guard all deselect_* calls with select.is_multiple
- Treat single-selects separately in shared utilities
- Reset single-selects by selecting another option, not deselecting
When it happens
Trigger: Calling `select.deselect_by_value('foo')` when the wrapped select lacks `multiple` (so `is_multiple` is False). The very first guard raises.
Common situations: 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.
Related errors
- You may only deselect all options of a multi-select
- Could not locate element with value: {value}
- You may only deselect all options of a multi-select
- You may only deselect options of a multi-select
- Select only works on <select> elements, not on {webelement.t
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/803eb71195e11086.
Report an issue: GitHub.