xpzouying/xiaohongshu-mcp · error
查找可见范围下拉框失败
Error message
查找可见范围下拉框失败
What it means
setVisibility wraps failure from page.Element("div.permission-card-wrapper div.d-select-content") when locating the visibility dropdown on the publish page. The visibility value was valid, but the dropdown selector did not resolve, usually meaning the permission card hasn't rendered or its DOM changed.
Source
Thrown at xiaohongshu/publish.go:890
return matched
}
// 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 {View on GitHub (pinned to 332d196854)
Solutions
- Wait for the permission card to appear before calling setVisibility (page.WaitElements or WaitStable).
- Dump the page HTML when this fires and update the selectors to the current classes.
- Ensure you're on the correct publish form page before invoking.
- Add a retry with delay since the section may render late.
Example fix
// before
dropdown, err := page.Element("div.permission-card-wrapper div.d-select-content")
// after
page.Timeout(10 * time.Second).WaitElements("div.permission-card-wrapper")
dropdown, err := page.Element("div.permission-card-wrapper div.d-select-content") Defensive patterns
Strategy: retry
Validate before calling
if _, err := page.Timeout(10*time.Second).Element("div.permission-card-wrapper"); err != nil { return errors.New("权限卡片未渲染") } Type guard
func permissionCardReady(p *rod.Page) bool { _, err := p.Element("div.permission-card-wrapper div.d-select-content"); return err == nil } Try / catch
if err := setVisibility(page, visibility); err != nil {
if strings.Contains(err.Error(), "查找可见范围下拉框失败") {
time.Sleep(2 * time.Second)
return setVisibility(page, visibility)
}
return err
} Prevention
- Wait for the form section before setting visibility
- Re-verify selectors after any XHS UI update
- Use element waits instead of fixed sleeps where possible
When it happens
Trigger: Calling submitPublish/submitPublishVideo before the publish form fully renders; page redesigned so permission-card-wrapper/d-select-content classes no longer exist; querying a page that navigated away.
Common situations: Xiaohongshu creator UI updates changing CSS class names; slow loading of the form section; running automation against a page variant (video vs article) with a different layout.
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/1c3798b9f4717aed.
Report an issue: GitHub.