jackwener/OpenCLI · error · CommandExecutionError

文字配图: could not click requested style "${styleName}".

Error message

文字配图: could not click requested style "${styleName}".

What it means

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.

Source

Thrown at clis/xiaohongshu/publish.js:963

          scroller.scrollTop = y;
          await new Promise((r) => setTimeout(r, 180));
          readAll();
          hit = target();
          if (hit) { reveal(hit); await new Promise((r) => setTimeout(r, 150)); return { ok: true, styles: seen, found: true }; }
        }
        scroller.scrollTop = 0;
      }
      return { ok: seen.length > 0, styles: seen, found: false };
    })()
  `));
    if (!available?.found) {
        throw new CommandExecutionError(`文字配图: requested style "${styleName}" is not available for this content `
            + `(options: ${(available?.styles || []).join(' / ') || 'none'}). `
            + `Choose an available style or omit --card-style to use ${DEFAULT_CARD_STYLE}.`);
    }
    const clicked = await clickByText(page, styleName);
    if (!clicked?.ok) {
        throw new CommandExecutionError(`文字配图: could not click requested style "${styleName}".`);
    }
    await page.wait({ time: 0.6 });
    return styleName;
}
/**
 * Count visible media in the current editor/composer. Text-image generation must
 * produce real image cards before we fill title/body or submit; otherwise a
 * no-op 生成图片 / 下一步 sequence can publish the wrong draft surface.
 */
async function currentComposerMediaCount(page) {
    const result = await page.evaluate(`
    (() => {
      const __opencli_xhs_composer_media_count = true;
      const visibleBox = (el) => {
        if (!el || el.offsetParent === null) return false;
        const r = el.getBoundingClientRect();
        return r.width > 0 && r.height > 0;
      };

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Retry the publish — the click race typically resolves on a second attempt.
  2. Scroll the style strip fully before selection or add a wait between scanning and clicking.
  3. Choose a different style or omit --card-style to use the default.
  4. If persistent, update clickByText to scrollIntoView + dispatch click events for the current XHS DOM.

Example fix

// before
await selectCardStyle(page, styleName);
// after
try {
  await selectCardStyle(page, styleName);
} catch (e) {
  if (/could not click requested style/.test(e.message)) {
    await page.wait({ time: 1.5 });
    await selectCardStyle(page, styleName);
  } else throw e;
}
Defensive patterns

Strategy: retry

Validate before calling

// confirm style strip finished loading before selecting
await page.wait({ time: 1.0 });
const ok = await scrollStyleStripToEnd(page);

Type guard

null

Try / catch

try { await selectCardStyle(page, styleName); }
catch (e) {
  if (/could not click requested style/.test(e.message)) {
    await page.wait({ time: 1.5 });
    await selectCardStyle(page, styleName);
  } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/6a826803a42a829c. Report an issue: GitHub.