{"record":{"id":"61a0cca60366ea9a","repo":"SeleniumHQ/selenium","slug":"cannot-locate-option-with-value-value-61a0cc","errorCode":null,"errorMessage":"Cannot locate option with value: {value}","messagePattern":"Cannot locate option with value: (.+?)","errorType":"exception","errorClass":"NoSuchElementException","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/support/select.py","lineNumber":85,"sourceCode":"\n                `<option value=\"foo\">Bar</option>`\n\n        Args:\n            value: The value to match against\n\n        Raises:\n            NoSuchElementException: If there is no option with specified value in SELECT\n        \"\"\"\n        css = f\"option[value ={self._escape_string(value)}]\"\n        opts = self._el.find_elements(By.CSS_SELECTOR, css)\n        matched = False\n        for opt in opts:\n            self._set_selected(opt)\n            if not self.is_multiple:\n                return\n            matched = True\n        if not matched:\n            raise NoSuchElementException(f\"Cannot locate option with value: {value}\")\n\n    def select_by_index(self, index: int) -> None:\n        \"\"\"Select the option at the given index by examining the \"index\" attribute.\n\n        Args:\n            index: The option at this index will be selected\n\n        Raises:\n            NoSuchElementException: If there is no option with specified index in SELECT\n        \"\"\"\n        match = str(index)\n        for opt in self.options:\n            if opt.get_attribute(\"index\") == match:\n                self._set_selected(opt)\n                return\n        raise NoSuchElementException(f\"Could not locate element with index {index}\")\n\n    def select_by_visible_text(self, text: str) -> None:","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/support/select.py#L67-L103","documentation":"`select_by_value()` builds a CSS selector `option[value=...]` and tries to select matching options. If none match it raises `NoSuchElementException` so the caller knows the requested value does not exist in the select.","triggerScenarios":"Calling `select.select_by_value('foo')` when no `<option value=\"foo\">` exists. Common when the value comes from test data that is stale, misspelled, or belongs to a different locale/environment.","commonSituations":"Value sourced from a config/env that differs across environments; trailing whitespace or case mismatch between data and the DOM attribute; the option is added dynamically and not yet present; hidden options that are present but the value string is wrong.","solutions":["Inspect the select's option values first: `[o.get_attribute('value') for o in select.options]`","Verify the value string matches exactly (case, whitespace)","Add an explicit wait for the option to be present before selecting","Catch NoSuchElementException and fall back to selecting by visible text or index"],"exampleFix":"// before\nselect.select_by_value(\"USA\")\n\n// after\nvalues = [o.get_attribute(\"value\") for o in select.options]\nif \"us\" in values:\n    select.select_by_value(\"us\")","handlingStrategy":"try-catch","validationCode":"values = [o.get_attribute(\"value\") for o in select.options]\nif value in values:\n    select.select_by_value(value)","typeGuard":"def value_exists(select_obj, value) -> bool:\n    return value in [o.get_attribute(\"value\") for o in select_obj.options]","tryCatchPattern":"from selenium.common.exceptions import NoSuchElementException\n\ntry:\n    select.select_by_value(value)\nexcept NoSuchElementException:\n    # value not present — handle/log\n    pass","preventionTips":["Snapshot option values before selecting from external data","Match value strings exactly (case and whitespace)","Add an explicit wait for the option when options load dynamically"],"tags":["select","element-not-found","selenium-python"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}