{"record":{"id":"ce2e329c226183c6","repo":"xpzouying/xiaohongshu-mcp","slug":"error-ce2e32","errorCode":null,"errorMessage":"查找可见范围选项失败","messagePattern":"查找可见范围选项失败","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"xiaohongshu/publish.go","lineNumber":900,"sourceCode":"\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 {\n\t\t\t\treturn errors.Wrap(err, \"选择可见范围失败\")\n\t\t\t}\n\t\t\tslog.Info(\"已设置可见范围\", \"visibility\", visibility)\n\t\t\ttime.Sleep(200 * time.Millisecond)\n\t\t\treturn nil\n\t\t}\n\t}\n\treturn errors.Errorf(\"未找到可见范围选项: %s\", visibility)\n}\n","sourceCodeStart":882,"sourceCodeEnd":918,"githubUrl":"https://github.com/xpzouying/xiaohongshu-mcp/blob/332d196854a9eac0d2b8c2c0e3d0cc43139d724c/xiaohongshu/publish.go#L882-L918","documentation":"setVisibility wraps failure from page.Elements(\"div.d-options-wrapper div.d-grid-item div.custom-option\") when listing the visibility options in the opened dropdown popup. The dropdown click succeeded but enumerating the option items failed at the CDP level.","triggerScenarios":"Options popup renders in a different container than expected (UI update), page navigated between click and query, or rod Elements query raced with popup animation.","commonSituations":"Creator UI redesign renaming d-options-wrapper/d-grid-item/custom-option; popup rendered lazily after the 500ms wait was too short; remote browser flakiness.","solutions":["Wait explicitly for div.d-options-wrapper to appear after clicking instead of a fixed 500ms sleep.","Inspect current DOM and refresh selectors after UI updates.","Retry the Elements query after a short delay (popup may still be animating in).","Ensure the click on the dropdown actually opened the popup before querying."],"exampleFix":"// before\ntime.Sleep(500 * time.Millisecond)\nopts, err := page.Elements(\"div.d-options-wrapper div.d-grid-item div.custom-option\")\n// after\ntime.Sleep(500 * time.Millisecond)\nif _, err := page.Element(\"div.d-options-wrapper\"); err != nil {\n    time.Sleep(1 * time.Second) // 弹窗可能尚未渲染\n}\nopts, err := page.Elements(\"div.d-options-wrapper div.d-grid-item div.custom-option\")","handlingStrategy":"retry","validationCode":"if _, err := page.Timeout(3*time.Second).Element(\"div.d-options-wrapper\"); err != nil { return errors.New(\"选项弹窗未出现\") }","typeGuard":"func optionsPopupOpen(p *rod.Page) bool { _, err := p.Element(\"div.d-options-wrapper div.custom-option\"); return err == nil }","tryCatchPattern":"opts, err := listVisibilityOptions(page) // 内部封装 Elements 查询\nif err != nil {\n    time.Sleep(1 * time.Second) // 弹窗动画后再试\n    opts, err = listVisibilityOptions(page)\n}","preventionTips":["Wait for the options wrapper instead of a fixed sleep","Refresh selectors when the creator UI updates","Retry transient DOM queries"],"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"}