{"record":{"id":"6a826803a42a829c","repo":"jackwener/OpenCLI","slug":"could-not-click-requested-style-stylename","errorCode":null,"errorMessage":"文字配图: could not click requested style \"${styleName}\".","messagePattern":"文字配图: could not click requested style \"(.+?)\"\\.","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/xiaohongshu/publish.js","lineNumber":963,"sourceCode":"          scroller.scrollTop = y;\n          await new Promise((r) => setTimeout(r, 180));\n          readAll();\n          hit = target();\n          if (hit) { reveal(hit); await new Promise((r) => setTimeout(r, 150)); return { ok: true, styles: seen, found: true }; }\n        }\n        scroller.scrollTop = 0;\n      }\n      return { ok: seen.length > 0, styles: seen, found: false };\n    })()\n  `));\n    if (!available?.found) {\n        throw new CommandExecutionError(`文字配图: requested style \"${styleName}\" is not available for this content `\n            + `(options: ${(available?.styles || []).join(' / ') || 'none'}). `\n            + `Choose an available style or omit --card-style to use ${DEFAULT_CARD_STYLE}.`);\n    }\n    const clicked = await clickByText(page, styleName);\n    if (!clicked?.ok) {\n        throw new CommandExecutionError(`文字配图: could not click requested style \"${styleName}\".`);\n    }\n    await page.wait({ time: 0.6 });\n    return styleName;\n}\n/**\n * Count visible media in the current editor/composer. Text-image generation must\n * produce real image cards before we fill title/body or submit; otherwise a\n * no-op 生成图片 / 下一步 sequence can publish the wrong draft surface.\n */\nasync function currentComposerMediaCount(page) {\n    const result = await page.evaluate(`\n    (() => {\n      const __opencli_xhs_composer_media_count = true;\n      const visibleBox = (el) => {\n        if (!el || el.offsetParent === null) return false;\n        const r = el.getBoundingClientRect();\n        return r.width > 0 && r.height > 0;\n      };","sourceCodeStart":945,"sourceCodeEnd":981,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/publish.js#L945-L981","documentation":"selectCardStyle found the requested style label in the strip (it passed the availability check) but clickByText could not actually click it, so it throws. This means the label is present but the click on its element failed.","triggerScenarios":"clickByText returned { ok: false } — the element was covered by an overlay, scrolled out of view between listing and clicking, is disabled, or the matched node isn't directly clickable.","commonSituations":"Style strip re-rendered between the availability scan and the click (lazy images shifting layout); a XHS tooltip/banner overlays the option; network slowness leaving the element detached; click intercepted by an animation.","solutions":["Retry the publish — the click race typically resolves on a second attempt.","Scroll the style strip fully before selection or add a wait between scanning and clicking.","Choose a different style or omit --card-style to use the default.","If persistent, update clickByText to scrollIntoView + dispatch click events for the current XHS DOM."],"exampleFix":"// before\nawait selectCardStyle(page, styleName);\n// after\ntry {\n  await selectCardStyle(page, styleName);\n} catch (e) {\n  if (/could not click requested style/.test(e.message)) {\n    await page.wait({ time: 1.5 });\n    await selectCardStyle(page, styleName);\n  } else throw e;\n}","handlingStrategy":"retry","validationCode":"// confirm style strip finished loading before selecting\nawait page.wait({ time: 1.0 });\nconst ok = await scrollStyleStripToEnd(page);","typeGuard":"null","tryCatchPattern":"try { await selectCardStyle(page, styleName); }\ncatch (e) {\n  if (/could not click requested style/.test(e.message)) {\n    await page.wait({ time: 1.5 });\n    await selectCardStyle(page, styleName);\n  } else throw e;\n}","preventionTips":["Scroll the style strip fully before clicking an option","Add a pause between scanning and clicking to avoid re-render races","Fall back to the default style on click failure"],"tags":["browser-automation","click-failure","ui-timing"],"backgroundTag":"element-click-intercepted","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}