{"record":{"id":"b06ecaa650e75977","repo":"xpzouying/xiaohongshu-mcp","slug":"error-b06eca","errorCode":null,"errorMessage":"查找定时发布开关失败","messagePattern":"查找定时发布开关失败","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"xiaohongshu/publish.go","lineNumber":940,"sourceCode":"\tif err := clickScheduleSwitch(page); err != nil {\n\t\treturn err\n\t}\n\ttime.Sleep(800 * time.Millisecond)\n\n\t// 2. 设置日期时间\n\tif err := setDateTime(ctx, page, t); err != nil {\n\t\treturn err\n\t}\n\ttime.Sleep(500 * time.Millisecond)\n\n\treturn nil\n}\n\n// clickScheduleSwitch 点击定时发布开关\nfunc clickScheduleSwitch(page *rod.Page) error {\n\tswitchElem, err := page.Element(\".post-time-wrapper .d-switch\")\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"查找定时发布开关失败\")\n\t}\n\n\tif err := humanize.Click(switchElem); err != nil {\n\t\treturn errors.Wrap(err, \"点击定时发布开关失败\")\n\t}\n\tslog.Info(\"已点击定时发布开关\")\n\treturn nil\n}\n\n// setDateTime 设置日期时间\nfunc setDateTime(ctx context.Context, page *rod.Page, t time.Time) error {\n\tdateTimeStr := t.Format(\"2006-01-02 15:04\")\n\n\telem, err := page.Element(\".date-picker-container input\")\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"查找日期时间输入框失败\")\n\t}\n","sourceCodeStart":922,"sourceCodeEnd":958,"githubUrl":"https://github.com/xpzouying/xiaohongshu-mcp/blob/332d196854a9eac0d2b8c2c0e3d0cc43139d724c/xiaohongshu/publish.go#L922-L958","documentation":"Thrown by clickScheduleSwitch when page.Element(\".post-time-wrapper .d-switch\") fails to locate the schedule-publish toggle on the Xiaohongshu creator upload page. rod's Element() waits up to its default timeout for the selector before erroring, so the element genuinely did not render in time or the page DOM no longer matches this selector.","triggerScenarios":"Calling setSchedulePublish when the publish flow is not at the settings stage, the upload page failed to fully load, XHS front-end updated the .post-time-wrapper markup, or the page navigated/closed mid-flow.","commonSituations":"Slow network on the creator page, a login or verification popup blocking the flow, XHS redesign changing class names, or running setSchedulePublish before content upload finished so the schedule section never rendered.","solutions":["Wait for the schedule section to render before calling setSchedulePublish (Wait on .post-time-wrapper).","Log page.HTML() on failure and verify .post-time-wrapper .d-switch still exists on the live XHS page; update the selector if XHS changed it.","Dismiss any login/verification popups before this step.","Increase the selector timeout with page.Timeout(...) if renders are consistently slow."],"exampleFix":"// before\nswitchElem, err := page.Element(\".post-time-wrapper .d-switch\")\n// after\nif err := page.Wait(\"() => !!document.querySelector('.post-time-wrapper')\"); err != nil {\n\treturn errors.Wrap(err, \"定时发布区域未渲染\")\n}\nswitchElem, err := page.Element(\".post-time-wrapper .d-switch\")","handlingStrategy":"validation","validationCode":"if err := page.Wait(\"() => !!document.querySelector('.post-time-wrapper .d-switch')\"); err != nil {\n\treturn fmt.Errorf(\"定时发布开关未渲染: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := setSchedulePublish(ctx, page, t); err != nil {\n\tif strings.Contains(err.Error(), \"查找定时发布开关失败\") {\n\t\thtml, _ := page.HTML()\n\t\tslog.Warn(\"schedule switch missing\", \"htmlLen\", len(html))\n\t\t// 重试或跳过定时设置\n\t}\n\treturn err\n}","preventionTips":["Wait for .post-time-wrapper to exist before schedule steps rather than relying on fixed sleeps.","Log page HTML when selectors fail to catch XHS markup changes quickly.","Keep selector constants centralized with a last-verified-date comment.","Handle login/verification popups before the publish flow."],"tags":["selector-not-found","go-rod","automation","ui-timeout"],"backgroundTag":"element-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"}