{"record":{"id":"acb20da4221ec59f","repo":"alibaba/page-agent","slug":"no-interactive-element-found-at-index-index","errorCode":null,"errorMessage":"No interactive element found at index ${index}","messagePattern":"No interactive element found at index (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/page-controller/src/actions.ts","lineNumber":29,"sourceCode":"\tisHTMLElement,\n\tisInputElement,\n\tisSelectElement,\n\tisTextAreaElement,\n\tmovePointerToElement,\n\twaitFor,\n} from './utils'\n\n/**\n * Get the HTMLElement by index from a selectorMap.\n * @private Internal method, subject to change at any time.\n */\nexport function getElementByIndex(\n\tselectorMap: Map<number, InteractiveElementDomNode>,\n\tindex: number\n): HTMLElement {\n\tconst interactiveNode = selectorMap.get(index)\n\tif (!interactiveNode) {\n\t\tthrow new Error(`No interactive element found at index ${index}`)\n\t}\n\n\tconst element = interactiveNode.ref\n\tif (!element) {\n\t\tthrow new Error(`Element at index ${index} does not have a reference`)\n\t}\n\n\tif (!isHTMLElement(element)) {\n\t\tthrow new Error(`Element at index ${index} is not an HTMLElement`)\n\t}\n\n\treturn element\n}\n\nlet lastClickedElement: HTMLElement | null = null\n\nfunction blurLastClickedElement() {\n\tif (lastClickedElement) {","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/alibaba/page-agent/blob/d02db1ee7c41f5315beda88bab2fe935c580f662/packages/page-controller/src/actions.ts#L11-L47","documentation":"This error is thrown by getElementByIndex when the selector map produced by updateTree() has no interactive element entry for the given index. Indexes only exist for elements the DOM extraction marked as interactive during the last indexing pass, so an unknown index means the caller is using a stale or invented number. It protects against silently acting on the wrong element.","triggerScenarios":"Calling clickElement/inputText/selectOption with an index not present in the current selectorMap; using indexes from a previous updateTree() run after the page changed; passing a raw DOM node index instead of an interactive-element index; hallucinated indexes from the LLM.","commonSituations":"Agent loop re-indexes between steps but reuses indexes from the older observation; page re-rendered (React/Vue) between observation and action; index parsing off-by-one; LLM output references an index that no longer exists.","solutions":["Re-run updateTree() and act on indexes from the fresh getSimplifiedHTML() output","Verify the index exists before acting: controller.element?.(index) or check the selector map via getPageInfo()","Make the agent retry with a fresh observation when an action fails with this error","Log the current simplified HTML alongside the failing index to spot staleness or hallucination"],"exampleFix":"// before\nawait controller.clickElement(42) // index no longer exists\n\n// after\nawait controller.updateTree()\nconst html = await controller.getSimplifiedHTML()\n// pick an index present in html, then:\nawait controller.clickElement(42)","handlingStrategy":"validation","validationCode":"const info = await controller.getPageInfo() // or getSimplifiedHTML(); confirm the index appears before acting","typeGuard":null,"tryCatchPattern":"try { await controller.clickElement(i) } catch (e) { if (/No interactive element found at index/.test(String(e))) { await controller.updateTree(); /* re-pick index */ } else throw e }","preventionTips":["Never reuse indexes across updateTree() generations","Derive indexes only from the latest getSimplifiedHTML() output","Retry with a fresh observation when index errors occur in agent loops"],"tags":["dom","page-controller","index","stale-state"],"backgroundTag":"index-out-of-bounds","analyzedSha":"d02db1ee7c41f5315beda88bab2fe935c580f662","analyzedAt":"2026-08-28T19:39:48.634Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}