{"record":{"id":"1c3798b9f4717aed","repo":"xpzouying/xiaohongshu-mcp","slug":"error-1c3798","errorCode":null,"errorMessage":"查找可见范围下拉框失败","messagePattern":"查找可见范围下拉框失败","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"xiaohongshu/publish.go","lineNumber":890,"sourceCode":"\treturn matched\n}\n\n// setVisibility 设置可见范围\n// 支持: \"公开可见\"(默认), \"仅自己可见\", \"仅互关好友可见\"\nfunc setVisibility(page *rod.Page, visibility string) error {\n\tif visibility == \"\" || visibility == \"公开可见\" {\n\t\tslog.Info(\"可见范围使用默认：公开可见\")\n\t\treturn nil\n\t}\n\n\tsupported := map[string]bool{\"仅自己可见\": true, \"仅互关好友可见\": true}\n\tif !supported[visibility] {\n\t\treturn errors.Errorf(\"不支持的可见范围: %s，支持: 公开可见、仅自己可见、仅互关好友可见\", visibility)\n\t}\n\n\tdropdown, err := page.Element(\"div.permission-card-wrapper div.d-select-content\")\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"查找可见范围下拉框失败\")\n\t}\n\tif err := humanize.Click(dropdown); err != nil {\n\t\treturn errors.Wrap(err, \"点击可见范围下拉框失败\")\n\t}\n\ttime.Sleep(500 * time.Millisecond)\n\n\t// 在弹窗中查找并点击目标选项\n\topts, err := page.Elements(\"div.d-options-wrapper div.d-grid-item div.custom-option\")\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"查找可见范围选项失败\")\n\t}\n\tfor _, opt := range opts {\n\t\ttext, err := opt.Text()\n\t\tif err != nil {\n\t\t\tcontinue\n\t\t}\n\t\tif strings.Contains(text, visibility) {\n\t\t\tif err := humanize.Click(opt); err != nil {","sourceCodeStart":872,"sourceCodeEnd":908,"githubUrl":"https://github.com/xpzouying/xiaohongshu-mcp/blob/332d196854a9eac0d2b8c2c0e3d0cc43139d724c/xiaohongshu/publish.go#L872-L908","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\ndropdown, err := page.Element(\"div.permission-card-wrapper div.d-select-content\")\n// after\npage.Timeout(10 * time.Second).WaitElements(\"div.permission-card-wrapper\")\ndropdown, err := page.Element(\"div.permission-card-wrapper div.d-select-content\")","handlingStrategy":"retry","validationCode":"if _, err := page.Timeout(10*time.Second).Element(\"div.permission-card-wrapper\"); err != nil { return errors.New(\"权限卡片未渲染\") }","typeGuard":"func permissionCardReady(p *rod.Page) bool { _, err := p.Element(\"div.permission-card-wrapper div.d-select-content\"); return err == nil }","tryCatchPattern":"if err := setVisibility(page, visibility); err != nil {\n    if strings.Contains(err.Error(), \"查找可见范围下拉框失败\") {\n        time.Sleep(2 * time.Second)\n        return setVisibility(page, visibility)\n    }\n    return err\n}","preventionTips":["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"],"tags":["browser-automation","rod","selector-not-found"],"backgroundTag":"selector-not-found","analyzedSha":"332d196854a9eac0d2b8c2c0e3d0cc43139d724c","analyzedAt":"2026-09-05T22:22:55.988Z","contentChangedAt":"2026-09-05T22:22:55.988Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}