{"record":{"id":"235fa31ccd875862","repo":"SeleniumHQ/selenium","slug":"select-only-works-on-select-elements-not-on-we","errorCode":null,"errorMessage":"Select only works on <select> elements, not on {webelement.tag_name}","messagePattern":"Select only works on <select> elements, not on (.+?)","errorType":"exception","errorClass":"UnexpectedTagNameException","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/support/select.py","lineNumber":39,"sourceCode":"from selenium.webdriver.remote.webelement import WebElement\n\n\nclass Select:\n    def __init__(self, webelement: WebElement) -> None:\n        \"\"\"Constructor. A check is made that the given element is a SELECT tag.\n\n        Args:\n            webelement: SELECT element to wrap\n\n        Example:\n            from selenium.webdriver.support.ui import Select\n            Select(driver.find_element(By.TAG_NAME, \"select\")).select_by_index(2)\n\n        Raises:\n            UnexpectedTagNameException: If the element is not a SELECT tag\n        \"\"\"\n        if webelement.tag_name.lower() != \"select\":\n            raise UnexpectedTagNameException(f\"Select only works on <select> elements, not on {webelement.tag_name}\")\n        self._el = webelement\n        multi = self._el.get_dom_attribute(\"multiple\")\n        self.is_multiple = multi and multi != \"false\"\n\n    @property\n    def options(self) -> list[WebElement]:\n        \"\"\"Returns a list of all options belonging to this select tag.\"\"\"\n        return self._el.find_elements(By.TAG_NAME, \"option\")\n\n    @property\n    def all_selected_options(self) -> list[WebElement]:\n        \"\"\"Return a list of all selected options belonging to this select tag.\"\"\"\n        return [opt for opt in self.options if opt.is_selected()]\n\n    @property\n    def first_selected_option(self) -> WebElement:\n        \"\"\"Return the first selected option or the currently selected option.\"\"\"\n        for opt in self.options:","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/support/select.py#L21-L57","documentation":"The `Select` helper only wraps genuine `<select>` elements. Its constructor checks `webelement.tag_name.lower() != 'select'` and raises `UnexpectedTagNameException` otherwise, because option-list semantics (multiple, options, select/deselect) only apply to select tags.","triggerScenarios":"Constructing `Select(el)` where `el` is a `<div>`, `<ul>`, or any non-select element — common with custom dropdown widgets built from divs. Also when the located element is a wrapper container rather than the actual select, or when the page changed and the locator now matches a different tag.","commonSituations":"Modern single-page apps use custom (div/ul-based) dropdowns that are not real `<select>` elements; the test grabbed a parent container; a locator matched a different element after a UI redesign; trying to use Select on a Shadow DOM custom component.","solutions":["Verify the element's tag is 'select' before constructing Select","Refine the locator to target the actual `<select>` element, e.g. `driver.find_element(By.TAG_NAME, 'select')`","If the dropdown is a custom widget, do not use Select — interact via click/keys directly","Inspect with `el.tag_name` to confirm which element was actually located"],"exampleFix":"// before\nel = driver.find_element(By.CSS_SELECTOR, \".dropdown\")\nselect = Select(el)\n\n// after\nel = driver.find_element(By.CSS_SELECTOR, \"select#country\")\nselect = Select(el)","handlingStrategy":"type-guard","validationCode":"el = driver.find_element(By.CSS_SELECTOR, \"select#country\")\nif el.tag_name.lower() != \"select\":\n    raise ValueError(f\"expected <select>, got <{el.tag_name}>\")\nselect = Select(el)","typeGuard":"def is_select_element(el) -> bool:\n    return getattr(el, \"tag_name\", \"\").lower() == \"select\"","tryCatchPattern":"from selenium.common.exceptions import UnexpectedTagNameException\n\ntry:\n    select = Select(el)\nexcept UnexpectedTagNameException:\n    # custom dropdown — interact directly\n    el.click()","preventionTips":["Always target the <select> tag explicitly in your locator","Check el.tag_name before constructing Select","Recognise custom div/ul dropdowns cannot use Select"],"tags":["select","validation","selenium-python"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}