xpzouying/xiaohongshu-mcp · error
选择可见范围失败
Error message
选择可见范围失败
What it means
setVisibility wraps failure from humanize.Click on the matched visibility option item. The option containing the requested visibility text was found but clicking it failed, so the setting was not applied. Stale element or click interception are the usual causes.
Source
Thrown at xiaohongshu/publish.go:909
}
if err := humanize.Click(dropdown); err != nil {
return errors.Wrap(err, "点击可见范围下拉框失败")
}
time.Sleep(500 * time.Millisecond)
// 在弹窗中查找并点击目标选项
opts, err := page.Elements("div.d-options-wrapper div.d-grid-item div.custom-option")
if err != nil {
return errors.Wrap(err, "查找可见范围选项失败")
}
for _, opt := range opts {
text, err := opt.Text()
if err != nil {
continue
}
if strings.Contains(text, visibility) {
if err := humanize.Click(opt); err != nil {
return errors.Wrap(err, "选择可见范围失败")
}
slog.Info("已设置可见范围", "visibility", visibility)
time.Sleep(200 * time.Millisecond)
return nil
}
}
return errors.Errorf("未找到可见范围选项: %s", visibility)
}
// setSchedulePublish 设置定时发布时间
func setSchedulePublish(ctx context.Context, page *rod.Page, t time.Time) error {
// 1. 点击定时发布开关
if err := clickScheduleSwitch(page); err != nil {
return err
}
time.Sleep(800 * time.Millisecond)
// 2. 设置日期时间View on GitHub (pinned to 332d196854)
Solutions
- Call opt.WaitStable before humanize.Click.
- Re-query the options and retry the click once.
- Increase the wait after opening the dropdown so the popup is fully interactive.
- Check for overlays that could swallow the click.
Example fix
// before
if err := humanize.Click(opt); err != nil {
return errors.Wrap(err, "选择可见范围失败")
}
// after
_ = opt.WaitStable(200 * time.Millisecond)
if err := humanize.Click(opt); err != nil {
return errors.Wrap(err, "选择可见范围失败")
} Defensive patterns
Strategy: retry
Validate before calling
if err := opt.WaitStable(200 * time.Millisecond); err != nil { continue } // 跳过不稳定项 Type guard
func clickable(e *rod.Element) bool { return e != nil && e.WaitStable(200*time.Millisecond) == nil } Try / catch
if err := setVisibility(page, v); err != nil {
if strings.Contains(err.Error(), "选择可见范围失败") {
time.Sleep(1 * time.Second)
return setVisibility(page, v)
}
return err
} Prevention
- Stabilize option elements before clicking
- Re-query options instead of reusing stale nodes
- Keep the dropdown popup focused during selection
When it happens
Trigger: Option item re-rendered between the Text() read and the Click; popup closed before the click; overlay intercepts pointer events; CDP click timeout.
Common situations: Popup auto-closes due to focus loss on slow environments; animations re-rendering option nodes; concurrent automation clicking elsewhere.
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/0baefd67cffc39eb.
Report an issue: GitHub.