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 = False

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Guard with `all_selected_options` first: `if select.all_selected_options: opt = select.first_selected_option`
  2. Catch NoSuchElementException and treat it as 'nothing selected' in your assertion flow
  3. 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

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


AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14). Data as JSON: /api/errors/d6849afccb63681c. Report an issue: GitHub.