xpzouying/xiaohongshu-mcp · error
点击原创声明开关失败
Error message
点击原创声明开关失败
What it means
Thrown by setOriginal when the original-declaration d-switch was located but humanize.Click on it failed. The element existed but the simulated click could not complete — typically invisibility, pointer interception by an overlay, or a stale/re-rendered node.
Source
Thrown at xiaohongshu/publish.go:1017
}
// 检查开关是否已打开
checked, err := switchElem.Eval(`() => {
const input = this.querySelector('input[type="checkbox"]');
return input ? input.checked : false;
}`)
if err != nil {
continue
}
if checked.Value.Bool() {
slog.Info("原创声明已开启")
return nil
}
// 点击开关
if err := humanize.Click(switchElem); err != nil {
return errors.Wrap(err, "点击原创声明开关失败")
}
time.Sleep(500 * time.Millisecond)
// 处理原创声明确认弹窗
if err := confirmOriginalDeclaration(page); err != nil {
return errors.Wrap(err, "确认原创声明失败")
}
slog.Info("已开启原创声明")
return nil
}
return errors.New("未找到原创声明选项")
}
// confirmOriginalDeclaration 交互(勾选须知、点声明按钮)走 go-rod 点击;
// 仅用只读 Eval 读取 checkbox 勾选态(不产生交互,无法用属性判断的自定义组件才用)。View on GitHub (pinned to 332d196854)
Solutions
- Scroll the card/switch into view before clicking.
- Re-query the switch element immediately before the click.
- Move the mouse away / dismiss any tooltip overlays before clicking.
- Retry the click once after a short wait.
Example fix
// before
if err := humanize.Click(switchElem); err != nil {
return errors.Wrap(err, "点击原创声明开关失败")
}
// after
switchElem.MustScrollIntoView()
time.Sleep(200 * time.Millisecond)
switchElem, err = card.Element("div.d-switch")
if err != nil {
return errors.Wrap(err, "点击原创声明开关失败")
}
if err := humanize.Click(switchElem); err != nil {
return errors.Wrap(err, "点击原创声明开关失败")
} Defensive patterns
Strategy: retry
Validate before calling
ok, err := page.Eval(`() => { const cards=[...document.querySelectorAll('div.custom-switch-card')]; const c=cards.find(x=>x.innerText.includes('原创声明')); if(!c) return false; const s=c.querySelector('div.d-switch'); return !!s && s.offsetParent !== null; }`)
if err != nil || !ok.Value.Bool() {
return fmt.Errorf("原创声明开关不可点击")
} Try / catch
if err := setOriginal(page); err != nil {
if strings.Contains(err.Error(), "点击原创声明开关失败") {
time.Sleep(1 * time.Second)
return setOriginal(page)
}
return err
} Prevention
- ScrollIntoView cards before clicking in small headless viewports.
- Re-query the switch immediately before the click.
- Check the switch state via read-only Eval before clicking; skip if already on.
- Avoid hovering tooltips before clicking the switch.
When it happens
Trigger: The switch is offscreen until scrolled into view; a tooltip on the span.has-tips intercepts the click; the card re-renders between lookup and click; page closed mid-click.
Common situations: Headless viewport too small so the card is offscreen; hover tooltips overlapping the switch; slow renders producing stale element handles.
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/7989765ce40f5579.
Report an issue: GitHub.