{"record":{"id":"cf953330fb7ae5ce","repo":"SeleniumHQ/selenium","slug":"could-not-locate-element-with-value-value","errorCode":null,"errorMessage":"Could not locate element with value: {value}","messagePattern":"Could not locate element with value: (.+?)","errorType":"exception","errorClass":"NoSuchElementException","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/support/select.py","lineNumber":182,"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        if not self.is_multiple:\n            raise NotImplementedError(\"You may only deselect options of a multi-select\")\n        matched = False\n        css = f\"option[value = {self._escape_string(value)}]\"\n        opts = self._el.find_elements(By.CSS_SELECTOR, css)\n        for opt in opts:\n            self._unset_selected(opt)\n            matched = True\n        if not matched:\n            raise NoSuchElementException(f\"Could not locate element with value: {value}\")\n\n    def deselect_by_index(self, index: int) -> None:\n        \"\"\"Deselect the option at the given index by examining the \"index\" attribute.\n\n        Args:\n            index: The option at this index will be deselected\n\n        Raises:\n            NoSuchElementException: If there is no option with specified index in SELECT\n        \"\"\"\n        if not self.is_multiple:\n            raise NotImplementedError(\"You may only deselect options of a multi-select\")\n        for opt in self.options:\n            if opt.get_attribute(\"index\") == str(index):\n                self._unset_selected(opt)\n                return\n        raise NoSuchElementException(f\"Could not locate element with index {index}\")\n","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/support/select.py#L164-L200","documentation":"`deselect_by_value()` builds `option[value=...]`, deselects matches, and if none matched raises `NoSuchElementException('Could not locate element with value: ...')`. The value simply does not exist among the (multi-select's) options.","triggerScenarios":"Calling `select.deselect_by_value('foo')` on a multi-select where no `<option value=\"foo\">` exists. The matched loop never sets `matched=True`.","commonSituations":"Stale config-driven values; case/whitespace mismatch; the option was removed dynamically; value belongs to a different select.","solutions":["List option values first: `[o.get_attribute('value') for o in select.options]`","Confirm the value string matches exactly","Catch NoSuchElementException and treat as 'already deselected / nothing to do'"],"exampleFix":"// before\nselect.deselect_by_value(\"USA\")\n\n// after\nvalues = [o.get_attribute(\"value\") for o in select.options]\nif \"us\" in values:\n    select.deselect_by_value(\"us\")","handlingStrategy":"try-catch","validationCode":"values = [o.get_attribute(\"value\") for o in select.options]\nif value in values:\n    select.deselect_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.deselect_by_value(value)\nexcept NoSuchElementException:\n    # nothing to deselect\n    pass","preventionTips":["Verify the value exists before deselecting","Treat NoSuchElementException as a no-op when already deselected","Match value strings exactly"],"tags":["select","multi-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"}