{"record":{"id":"2df93cd9f99cf9b0","repo":"n8n-io/n8n","slug":"select-failed","errorCode":null,"errorMessage":"select failed","messagePattern":"select failed","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/mcp-browser/src/adapters/agent-browser.ts","lineNumber":382,"sourceCode":"\n\t\tif (options?.submit) await this.runAction(['press', 'Enter']);\n\t}\n\n\tasync select(pageId: string, target: ElementTarget, values: string[]): Promise<string[]> {\n\t\tawait this.switchToTab(pageId);\n\t\t// Click to focus the <select> element (agent-browser does not inject aria-ref attributes)\n\t\tawait this.runAction(['click', this.resolveTarget(target)]);\n\t\t// Set the value on document.activeElement, which is the <select> after click\n\t\tconst script =\n\t\t\t'(function(){' +\n\t\t\t'const el=document.activeElement;' +\n\t\t\t'if(!el||el.tagName!==\"SELECT\")return[];' +\n\t\t\t`const v=${JSON.stringify(values)};` +\n\t\t\t'Array.from(el.options).forEach(o=>o.selected=v.includes(o.value)||v.includes(o.text.trim()));' +\n\t\t\t\"el.dispatchEvent(new Event('change',{bubbles:true}));\" +\n\t\t\t'return Array.from(el.selectedOptions).map(o=>o.value);})()';\n\t\tconst resp = await this.run(['eval', script]);\n\t\tif (!resp.success) throw new Error(resp.error ?? 'select failed');\n\t\treturn Array.isArray(resp.data) ? (resp.data as string[]) : values;\n\t}\n\n\tasync hover(pageId: string, target: ElementTarget): Promise<void> {\n\t\tawait this.switchToTab(pageId);\n\t\tawait this.runAction(['hover', this.resolveTarget(target)]);\n\t}\n\n\tasync press(pageId: string, keys: string): Promise<void> {\n\t\tAgentBrowserAdapter.assertSafeArg(keys, 'key');\n\t\tawait this.switchToTab(pageId);\n\t\tawait this.runAction(['press', keys]);\n\t}\n\n\tasync drag(_pageId: string, _from: ElementTarget, _to: ElementTarget): Promise<void> {\n\t\tawait Promise.resolve();\n\t\tthrow new UnsupportedOperationError('drag', this.name);\n\t}","sourceCodeStart":364,"sourceCodeEnd":400,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/mcp-browser/src/adapters/agent-browser.ts#L364-L400","documentation":"Thrown by AgentBrowserAdapter.select as the fallback message when the `eval` command that sets the <select> value returned success === false with no error field. The select() method clicks the element first (to focus the SELECT), then runs an eval script that sets option.selected and dispatches a change event. The literal 'select failed' only appears when resp.error is null/undefined.","triggerScenarios":"Calling adapter.select(pageId, target, values) where the click on the target succeeds but the subsequent `agent-browser eval` of the selection script returns { success: false } with no error string. Happens when the focused activeElement is not a SELECT, or the eval hits a page navigation/security error and the CLI drops the message.","commonSituations":"The target was not actually a <select> after the click (e.g. it was a custom dropdown), so the eval's guard `if(!el||el.tagName!==\"SELECT\")return[]` returns empty; a page navigation happened between click and eval; the agent-browser CLI version changed its eval response shape.","solutions":["Take a fresh snapshot and confirm the target ref points to a real <select> element before calling select().","For custom dropdown components, use click() to open and click() on options instead of select().","Upgrade/pin the agent-browser CLI version to match the adapter's expected eval response shape.","Check the gateway logs for the eval command that failed."],"exampleFix":"// before — calling select on a custom dropdown\nawait adapter.select(pageId, { ref: '@e5' }, ['opt1']);\n\n// after — confirm it's a SELECT first, fall back to clicks\nconst snap = await adapter.snapshot(pageId);\nif (!/@e5[^]*SELECT/.test(snap.tree)) {\n  await adapter.click(pageId, { ref: '@e5' }); // open\n  await adapter.click(pageId, { ref: '@e9' }); // option\n} else {\n  await adapter.select(pageId, { ref: '@e5' }, ['opt1']);\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":"function isSelectFailure(error: unknown): boolean {\n  return error instanceof Error && /select failed/.test(error.message);\n}","tryCatchPattern":"try {\n  return await adapter.select(pageId, target, values);\n} catch (err) {\n  if (isSelectFailure(err)) {\n    // custom dropdown — click to open, then click options\n    await adapter.click(pageId, target);\n  } else throw err;\n}","preventionTips":["Confirm the target is a real <select> via snapshot before calling select().","For custom dropdowns, use click() sequences instead of select().","Pin the agent-browser CLI version for a stable eval response shape."],"tags":["mcp-browser","agent-browser","interaction","select","form"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}