xpzouying/xiaohongshu-mcp · error
点击可见范围下拉框失败
Error message
点击可见范围下拉框失败
What it means
setVisibility wraps failure from humanize.Click on the visibility dropdown element. The dropdown was found but the click action failed, so the options popup never opens. Typically a stale-element or overlay-interception problem.
Source
Thrown at xiaohongshu/publish.go:893
// setVisibility 设置可见范围
// 支持: "公开可见"(默认), "仅自己可见", "仅互关好友可见"
func setVisibility(page *rod.Page, visibility string) error {
if visibility == "" || visibility == "公开可见" {
slog.Info("可见范围使用默认:公开可见")
return nil
}
supported := map[string]bool{"仅自己可见": true, "仅互关好友可见": true}
if !supported[visibility] {
return errors.Errorf("不支持的可见范围: %s,支持: 公开可见、仅自己可见、仅互关好友可见", visibility)
}
dropdown, err := page.Element("div.permission-card-wrapper div.d-select-content")
if err != nil {
return errors.Wrap(err, "查找可见范围下拉框失败")
}
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)View on GitHub (pinned to 332d196854)
Solutions
- Call dropdown.WaitStable(200ms) before humanize.Click.
- Dismiss any overlapping overlays before setting visibility.
- Re-locate the dropdown and retry the click once.
- Increase rod CDP timeouts.
Example fix
// before
if err := humanize.Click(dropdown); err != nil {
return errors.Wrap(err, "点击可见范围下拉框失败")
}
// after
if err := dropdown.WaitStable(300 * time.Millisecond); err != nil {
return errors.Wrap(err, "下拉框未稳定")
}
if err := humanize.Click(dropdown); err != nil {
return errors.Wrap(err, "点击可见范围下拉框失败")
} Defensive patterns
Strategy: retry
Validate before calling
if err := dropdown.WaitStable(300 * time.Millisecond); err != nil { return errors.Wrap(err, "下拉框未稳定") } 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 elements before clicking
- Dismiss overlays/popups before interacting
- Increase CDP timeouts on slow browsers
When it happens
Trigger: The d-select-content element was re-rendered between Element() and Click; another overlay (cookie banner, modal) intercepts the click; CDP click timed out on a slow browser.
Common situations: Animations re-rendering the select right at click time; heavy page load starving the browser; remote browser with high CDP latency.
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/57c419beeae40826.
Report an issue: GitHub.