SeleniumHQ/selenium · error · NoSuchElementException
No options are selected
Error message
No options are selected
What it means
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.
Source
Thrown at py/selenium/webdriver/support/select.py:60
self.is_multiple = multi and multi != "false"
@property
def options(self) -> list[WebElement]:
"""Returns a list of all options belonging to this select tag."""
return self._el.find_elements(By.TAG_NAME, "option")
@property
def all_selected_options(self) -> list[WebElement]:
"""Return a list of all selected options belonging to this select tag."""
return [opt for opt in self.options if opt.is_selected()]
@property
def first_selected_option(self) -> WebElement:
"""Return the first selected option or the currently selected option."""
for opt in self.options:
if opt.is_selected():
return opt
raise NoSuchElementException("No options are selected")
def select_by_value(self, value: str) -> None:
"""Select all options that have a value matching the argument.
Example:
When given "foo" this would select 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
"""
css = f"option[value ={self._escape_string(value)}]"
opts = self._el.find_elements(By.CSS_SELECTOR, css)
matched = FalseView on GitHub (pinned to aa36b38e69)
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
Example fix
// before opt = select.first_selected_option // after selected = select.all_selected_options opt = selected[0] if selected else None
Defensive patterns
Strategy: try-catch
Validate before calling
if select.all_selected_options:
opt = select.first_selected_option
else:
opt = None Type guard
def has_selected(select_obj) -> bool:
return len(select_obj.all_selected_options) > 0 Try / catch
from selenium.common.exceptions import NoSuchElementException
try:
opt = select.first_selected_option
except NoSuchElementException:
opt = None # nothing selected Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Select only works on <select> elements, not on {webelement.t
- Cannot locate option with value: {value}
- Could not locate element with index {index}
- Invisible option with text: {text}
- Could not locate element with visible text: {text}
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/d6849afccb63681c.
Report an issue: GitHub.