{"record":{"id":"277ed9b2caa484e3","repo":"jackwener/OpenCLI","slug":"could-not-find-the-chatgpt-target-label-tool-op","errorCode":null,"errorMessage":"Could not find the ChatGPT ${target.label} tool option.","messagePattern":"Could not find the ChatGPT (.+?) tool option\\.","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/chatgpt/utils.js","lineNumber":918,"sourceCode":"                ];\n                return haystacks.some(matchesLabel);\n            });\n            if (!(option instanceof HTMLElement)) return { found: false };\n            const checked = option.getAttribute('aria-checked') === 'true' || option.getAttribute('aria-selected') === 'true';\n            option.scrollIntoView({ block: 'center', inline: 'center' });\n            const rect = option.getBoundingClientRect();\n            return {\n                found: true,\n                checked,\n                x: Math.round(rect.left + rect.width / 2),\n                y: Math.round(rect.top + rect.height / 2),\n            };\n        })()`)), 'chatgpt tool option click');\n        if (optionCenter.found) break;\n        await page.wait(0.5);\n    }\n    if (!optionCenter?.found) {\n        throw new CommandExecutionError(`Could not find the ChatGPT ${target.label} tool option.`);\n    }\n    if (!optionCenter.checked) {\n        await page.nativeClick(Number(optionCenter.x), Number(optionCenter.y));\n    }\n\n    await page.wait(0.5);\n    const after = await getCurrentChatGPTTool(page);\n    if (after.tool !== target.key) {\n        throw new CommandExecutionError(`ChatGPT tool did not switch to ${target.label}.`);\n    }\n    return { Status: optionCenter.checked ? 'Already selected' : 'Success', Tool: target.label };\n}\n\nexport async function clearChatGPTDraft(page) {\n    await page.evaluate(`\n        (() => {\n            const removeLabels = [/^remove file/i, /^移除文件/];\n            for (let pass = 0; pass < 10; pass += 1) {","sourceCodeStart":900,"sourceCodeEnd":936,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/chatgpt/utils.js#L900-L936","documentation":"selectChatGPTTool automates selecting a tool (e.g. web search, image gen) in the ChatGPT UI by repeatedly trying to locate and check the tool's option element. It throws this CommandExecutionError when, after retrying, it cannot find a clickable option matching the requested target.label on the page.","triggerScenarios":"Calling selectedTool for a target whose option button is absent: ChatGPT UI changed/moved the tools menu, the prompt box has no tools menu in the current mode, the label text changed upstream (locale/branding), or the page did not finish loading before the retry loop exhausted.","commonSituations":"ChatGPT A/B UI rollout renamed or relocated the tools menu; automation running against a logged-out or capped account where tools are unavailable; stale page after navigation so the menu never renders; timeout too short for slow loading.","solutions":["Update/re-run on a freshly loaded chatgpt.com page and verify the tool option exists in the UI manually","Retry with longer waits between attempts (the loop waits 0.5s per try)","Check whether the ChatGPT UI/layout changed and update the selector/option-click automation in utils.js","Confirm the account actually has the requested tool available (some tools are plan- or region-gated)","If the tool is already active in the UI, skip selectChatGPTTool"],"exampleFix":"// before\nawait selectChatGPTTool(page, { key: 'search', label: 'Web search' });\n// after\nawait page.wait(2); // let the composer fully render\nawait selectChatGPTTool(page, { key: 'search', label: 'Web search' });","handlingStrategy":"retry","validationCode":"const current = await getCurrentChatGPTTool(page);\nif (current.tool === target.key) return { Status: 'Already selected', Tool: target.label };\nif (!(await page.locator('composer tools menu visible'))) throw new Error('Tools menu not rendered; reload page before selectChatGPTTool');","typeGuard":"function isToolTarget(t) {\n  return typeof t === 'object' && t !== null && typeof t.key === 'string' && typeof t.label === 'string';\n}","tryCatchPattern":"try {\n  await selectChatGPTTool(page, target);\n} catch (err) {\n  if (err instanceof CommandExecutionError && /tool option/.test(err.message)) {\n    await page.reload();\n    await selectChatGPTTool(page, target); // retry once on fresh page\n  } else throw err;\n}","preventionTips":["Wait for the composer to fully render before selecting a tool","Verify the tool exists in the current UI mode before targeting it","Keep selectors/labels updated when ChatGPT changes its UI","Pre-check current tool with getCurrentChatGPTTool to skip needless selection"],"tags":["automation","chatgpt","ui-selector","dom-not-found"],"backgroundTag":"ui-element-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}