{"record":{"id":"10ab24e8c99259ad","repo":"xpzouying/xiaohongshu-mcp","slug":"error-10ab24","errorCode":null,"errorMessage":"点击定时发布开关失败","messagePattern":"点击定时发布开关失败","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"xiaohongshu/publish.go","lineNumber":944,"sourceCode":"\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\n\t// SelectAllText 走 Eval(this.select())，只改选区、不额外派发事件，暂时保留。\n\t// 换成键盘全选要区分 Ctrl/Cmd，换成三击又可能触发日期控件的其他行为。\n\tif err := elem.SelectAllText(); err != nil {\n\t\treturn errors.Wrap(err, \"选择日期时间文本失败\")","sourceCodeStart":926,"sourceCodeEnd":962,"githubUrl":"https://github.com/xpzouying/xiaohongshu-mcp/blob/332d196854a9eac0d2b8c2c0e3d0cc43139d724c/xiaohongshu/publish.go#L926-L962","documentation":"Thrown by clickScheduleSwitch when the toggle element was found but humanize.Click could not complete the click. The element existed but the simulated interaction failed — typically because it was not visible/interactable, was detached and re-rendered, or the click was intercepted.","triggerScenarios":"The .d-switch is hidden until the schedule section is expanded, the element is re-rendered between lookup and click (stale node), an overlay intercepts the pointer, or the page/browser context closed mid-click.","commonSituations":"Switch offscreen in a small/headless viewport; anti-automation overlays; page navigation during automation; stale element handles from earlier re-renders.","solutions":["Scroll the element into view before clicking.","Re-query the element immediately before clicking to avoid a stale node.","Close any overlaying popups before this step.","Retry the click once after a short wait; if it persists, inspect live DOM state at failure time."],"exampleFix":"// before\nif err := humanize.Click(switchElem); err != nil {\n\treturn errors.Wrap(err, \"点击定时发布开关失败\")\n}\n// after\nswitchElem.MustScrollIntoView()\nswitchElem, err = page.Element(\".post-time-wrapper .d-switch\")\nif err != nil {\n\treturn errors.Wrap(err, \"查找定时发布开关失败\")\n}\nif err := humanize.Click(switchElem); err != nil {\n\treturn errors.Wrap(err, \"点击定时发布开关失败\")\n}","handlingStrategy":"retry","validationCode":"ready, err := page.Eval(`() => { const el = document.querySelector('.post-time-wrapper .d-switch'); return !!el && el.offsetParent !== null; }`)\nif !ready.Value.Bool() {\n\treturn fmt.Errorf(\"定时发布开关不可点击\")\n}","typeGuard":null,"tryCatchPattern":"for i := 0; i < 2; i++ {\n\tif err := clickScheduleSwitch(page); err == nil {\n\t\tbreak\n\t} else if i == 1 {\n\t\treturn fmt.Errorf(\"点击定时发布开关失败: %w\", err)\n\t}\n\ttime.Sleep(1 * time.Second)\n}","preventionTips":["Scroll elements into view before clicking in headless/small viewports.","Re-query elements right before interaction to avoid stale handles.","Dismiss tooltip/popover overlays before clicking switches.","Use humanize.Click consistently so click behavior stays uniform."],"tags":["click-failed","go-rod","automation","stale-element"],"backgroundTag":"element-click-failed","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"}