{"record":{"id":"86d8577638589a05","repo":"SeleniumHQ/selenium","slug":"invisible-option-with-text-text","errorCode":null,"errorMessage":"Invisible option with text: {text}","messagePattern":"Invisible option with text: (.+?)","errorType":"exception","errorClass":"NoSuchElementException","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/support/select.py","lineNumber":122,"sourceCode":"        \"\"\"Select all options that display text matching the argument.\n\n        Example:\n            When given \"Bar\" this would select an option like:\n\n            `<option value=\"foo\">Bar</option>`\n\n        Args:\n            text: The visible text to match against\n\n        Raises:\n            NoSuchElementException: If there is no option with specified text in SELECT\n        \"\"\"\n        xpath = f\".//option[normalize-space(.) = {self._escape_string(text)}]\"\n        opts = self._el.find_elements(By.XPATH, xpath)\n        matched = False\n        for opt in opts:\n            if not self._has_css_property_and_visible(opt):\n                raise NoSuchElementException(f\"Invisible option with text: {text}\")\n            self._set_selected(opt)\n            if not self.is_multiple:\n                return\n            matched = True\n\n        if len(opts) == 0 and \" \" in text:\n            sub_string_without_space = self._get_longest_token(text)\n            if sub_string_without_space == \"\":\n                candidates = self.options\n            else:\n                xpath = f\".//option[contains(.,{self._escape_string(sub_string_without_space)})]\"\n                candidates = self._el.find_elements(By.XPATH, xpath)\n            for candidate in candidates:\n                if text == candidate.text:\n                    if not self._has_css_property_and_visible(candidate):\n                        raise NoSuchElementException(f\"Invisible option with text: {text}\")\n                    self._set_selected(candidate)\n                    if not self.is_multiple:","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/support/select.py#L104-L140","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Scroll/expand the parent group or make the option visible before selecting","Use `select_by_value` if the value attribute is known and the option is enabled","Verify visibility: `option.value_of_css_property('display')` is not 'none'","Catch the exception and retry after interacting with the widget to reveal options"],"exampleFix":"// before\nselect.select_by_visible_text(\"Bar\")\n\n// after\nopt = select._el.find_element(By.XPATH, \".//option[normalize-space(.)='Bar']\")\ndriver.execute_script(\"arguments[0].style.display='block';\", opt)\nselect.select_by_visible_text(\"Bar\")","handlingStrategy":"try-catch","validationCode":"opt = select._el.find_element(By.XPATH, f\".//option[normalize-space(.)={select._escape_string(text)}]\")\nif opt.is_displayed():\n    select.select_by_visible_text(text)","typeGuard":"def option_visible(select_obj, text) -> bool:\n    for o in select_obj.options:\n        if o.text == text:\n            return o.is_displayed()\n    return False","tryCatchPattern":"from selenium.common.exceptions import NoSuchElementException\n\ntry:\n    select.select_by_visible_text(text)\nexcept NoSuchElementException as e:\n    if \"Invisible\" in str(e):\n        # reveal option then retry\n        pass","preventionTips":["Expand parent groups before selecting hidden options","Check option.is_displayed() before selecting by text","Use select_by_value when the option may be CSS-hidden"],"tags":["select","visibility","selenium-python"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}