{"record":{"id":"30d56200acf186d7","repo":"alibaba/page-agent","slug":"option-with-text-optiontext-not-found-in-sele","errorCode":null,"errorMessage":"Option with text \"${optionText}\" not found in select element","messagePattern":"Option with text \"(.+?)\" not found in select element","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/page-controller/src/actions.ts","lineNumber":247,"sourceCode":"\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}\n\n/**\n * @private Internal method, subject to change at any time.\n */\nexport async function scrollIntoViewIfNeeded(element: Element) {\n\tconst el = element as ScrollableElement\n\tif (typeof el.scrollIntoViewIfNeeded === 'function') {","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/alibaba/page-agent/blob/d02db1ee7c41f5315beda88bab2fe935c580f662/packages/page-controller/src/actions.ts#L229-L265","documentation":"selectOptionElement searched all <option> children of the select element and none had textContent matching (trimmed) the provided optionText, so it throws. The match is on the option's visible text, not its value attribute. This guards against silently selecting nothing or the wrong option.","triggerScenarios":"Passing the option's value attribute instead of its label text (value='US' vs text 'United States'); whitespace/casing/nested-markup differences in option text; the option list is populated lazily and not yet loaded; typo in the text.","commonSituations":"Agent reads the simplified HTML and copies an abbreviated or truncated option label; dynamically populated selects (fetch options after open) where options aren't rendered yet; localization changed option text; option text contains extra whitespace or child span markup.","solutions":["Use the exact visible label text from the current options (re-check getSimplifiedHTML or the select's options after updateTree)","For lazy selects, click the select once to trigger loading, re-index, then selectOption with the now-present option text","Trim and case-match your string; avoid passing the value attribute","If exact text is unstable, fall back to clickElement on the desired option after opening the select"],"exampleFix":"// before\nawait controller.selectOption(8, 'US') // option text is 'United States'\n\n// after\nawait controller.selectOption(8, 'United States')","handlingStrategy":"validation","validationCode":"const el = await controller.element(i); if (el instanceof HTMLSelectElement) { const ok = [...el.options].some(o => (o.textContent ?? '').trim() === myText.trim()); if (ok) await controller.selectOption(i, myText) }","typeGuard":null,"tryCatchPattern":"try { await controller.selectOption(i, text) } catch (e) { if (String(e).includes('not found in select element')) { /* re-read current option labels and retry with exact text */ } else throw e }","preventionTips":["Pass the option's visible label, not its value attribute","Trim your text and match casing exactly","For lazily loaded options, open the select, re-index, then select"],"tags":["dom","select","option-not-found","page-controller"],"backgroundTag":"option-value-mismatch","analyzedSha":"d02db1ee7c41f5315beda88bab2fe935c580f662","analyzedAt":"2026-08-28T19:39:48.634Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}