SeleniumHQ/selenium · error · NoSuchElementException

Invisible option with text: {text}

Error message

Invisible option with text: {text}

What it means

`select_by_visible_text()` first finds options whose normalised text equals the argument, then for each checks visibility via `_has_css_property_and_visible`. If a matching option exists but is hidden (visibility:hidden, display:none, opacity:0) it raises `NoSuchElementException('Invisible option with text: ...')` rather than selecting it.

Source

Thrown at py/selenium/webdriver/support/select.py:122

        """Select all options that display text matching the argument.

        Example:
            When given "Bar" this would select an option like:

            `<option value="foo">Bar</option>`

        Args:
            text: The visible text to match against

        Raises:
            NoSuchElementException: If there is no option with specified text in SELECT
        """
        xpath = f".//option[normalize-space(.) = {self._escape_string(text)}]"
        opts = self._el.find_elements(By.XPATH, xpath)
        matched = False
        for opt in opts:
            if not self._has_css_property_and_visible(opt):
                raise NoSuchElementException(f"Invisible option with text: {text}")
            self._set_selected(opt)
            if not self.is_multiple:
                return
            matched = True

        if len(opts) == 0 and " " in text:
            sub_string_without_space = self._get_longest_token(text)
            if sub_string_without_space == "":
                candidates = self.options
            else:
                xpath = f".//option[contains(.,{self._escape_string(sub_string_without_space)})]"
                candidates = self._el.find_elements(By.XPATH, xpath)
            for candidate in candidates:
                if text == candidate.text:
                    if not self._has_css_property_and_visible(candidate):
                        raise NoSuchElementException(f"Invisible option with text: {text}")
                    self._set_selected(candidate)
                    if not self.is_multiple:

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Scroll/expand the parent group or make the option visible before selecting
  2. Use `select_by_value` if the value attribute is known and the option is enabled
  3. Verify visibility: `option.value_of_css_property('display')` is not 'none'
  4. Catch the exception and retry after interacting with the widget to reveal options

Example fix

// before
select.select_by_visible_text("Bar")

// after
opt = select._el.find_element(By.XPATH, ".//option[normalize-space(.)='Bar']")
driver.execute_script("arguments[0].style.display='block';", opt)
select.select_by_visible_text("Bar")
Defensive patterns

Strategy: try-catch

Validate before calling

opt = select._el.find_element(By.XPATH, f".//option[normalize-space(.)={select._escape_string(text)}]")
if opt.is_displayed():
    select.select_by_visible_text(text)

Type guard

def option_visible(select_obj, text) -> bool:
    for o in select_obj.options:
        if o.text == text:
            return o.is_displayed()
    return False

Try / catch

from selenium.common.exceptions import NoSuchElementException

try:
    select.select_by_visible_text(text)
except NoSuchElementException as e:
    if "Invisible" in str(e):
        # reveal option then retry
        pass

Prevention

When it happens

Trigger: Calling `select.select_by_visible_text('Bar')` where an `<option>Bar</option>` exists but is hidden by CSS (display:none, visibility:hidden, or opacity:0). The text match succeeds but the visibility check fails.

Common situations: Options hidden until a parent group is expanded; conditionally-rendered options; CSS that hides certain options by default; the option is present in DOM but not interactable.

Related errors


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