{"record":{"id":"2c865f6565bfcdc9","repo":"alibaba/page-agent","slug":"element-is-not-a-select-element","errorCode":null,"errorMessage":"Element is not a select element","messagePattern":"Element is not a select element","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/page-controller/src/actions.ts","lineNumber":240,"sourceCode":"\t}\n\n\t// Only dispatch shared input event for non-contenteditable (contenteditable has its own)\n\tif (!isContentEditable) {\n\t\telement.dispatchEvent(new Event('input', { bubbles: true }))\n\t}\n\n\tawait waitFor(0.1)\n\n\tblurLastClickedElement()\n}\n\n/**\n * @todo browser-use version is very complex and supports menu tags, need to follow up\n * @private Internal method, subject to change at any time.\n */\nexport async function selectOptionElement(selectElement: HTMLSelectElement, optionText: string) {\n\tif (!isSelectElement(selectElement)) {\n\t\tthrow new Error('Element is not a select element')\n\t}\n\n\tconst options = Array.from(selectElement.options)\n\tconst option = options.find((opt) => opt.textContent?.trim() === optionText.trim())\n\n\tif (!option) {\n\t\tthrow new Error(`Option with text \"${optionText}\" not found in select element`)\n\t}\n\n\tselectElement.value = option.value\n\tselectElement.dispatchEvent(new Event('change', { bubbles: true }))\n\n\tawait waitFor(0.1) // Wait to ensure change event processing completes\n}\n\ninterface ScrollableElement extends Element {\n\tscrollIntoViewIfNeeded?: (centerIfNeeded?: boolean) => void\n}","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/alibaba/page-agent/blob/d02db1ee7c41f5315beda88bab2fe935c580f662/packages/page-controller/src/actions.ts#L222-L258","documentation":"selectOptionElement requires an actual <select> element and throws when the passed element fails isSelectElement. Custom dropdowns built from divs/ul/li are not <select>, so option selection by value/text cannot work on them. The library explicitly rejects them rather than misfiring click sequences.","triggerScenarios":"Calling selectOption with an index that points to a custom dropdown container (div[role=combobox], ul, button) instead of a native <select>; passing an HTMLElement you obtained yourself that is not a select; the native select was replaced by a widget at that index after re-render.","commonSituations":"Modern UI libraries (MUI, Ant Design, custom components) render div-based dropdowns; the agent sees a dropdown in the DOM and assumes selectOption applies; index staleness after re-render swapped the node.","solutions":["Check the element at that index: if it is not <select>, use clickElement to open the dropdown and click the option item instead","Verify with the simplified HTML that a native <select> exists before calling selectOption","Re-run updateTree() if the DOM may have changed since observation","Wrap selectOption in try-catch and fall back to a click-through sequence for custom dropdowns"],"exampleFix":"// before\nawait controller.selectOption(8, 'United States') // index 8 is a div dropdown\n\n// after (custom dropdown): open and click the option\nawait controller.clickElement(8) // open dropdown\nawait controller.updateTree()\nawait controller.clickElement(21) // click desired option li/div","handlingStrategy":"type-guard","validationCode":"const el = await controller.element(i); if (!(el instanceof HTMLSelectElement)) { /* use click-through sequence instead of selectOption */ }","typeGuard":"function isNativeSelect(el: HTMLElement | null): el is HTMLSelectElement { return el instanceof HTMLSelectElement }","tryCatchPattern":"try { await controller.selectOption(i, text) } catch (e) { if (String(e).includes('not a select element')) { await controller.clickElement(i); await controller.updateTree(); await controller.clickElement(optionIndex) } else throw e }","preventionTips":["Check for <select> in the simplified HTML before choosing selectOption","Assume modern component libraries use div dropdowns; plan a click fallback","Re-index after opening custom dropdowns"],"tags":["dom","select","dropdown","page-controller"],"backgroundTag":"element-type-mismatch","analyzedSha":"d02db1ee7c41f5315beda88bab2fe935c580f662","analyzedAt":"2026-08-28T19:39:48.634Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}