{"record":{"id":"744f7f4d4dfb80f6","repo":"xpzouying/xiaohongshu-mcp","slug":"error-744f7f","errorCode":null,"errorMessage":"输入日期时间失败","messagePattern":"输入日期时间失败","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"xiaohongshu/publish.go","lineNumber":965,"sourceCode":"\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, \"选择日期时间文本失败\")\n\t}\n\tif err := humanize.Type(ctx, elem, dateTimeStr); err != nil {\n\t\treturn errors.Wrap(err, \"输入日期时间失败\")\n\t}\n\tslog.Info(\"已设置日期时间\", \"datetime\", dateTimeStr)\n\n\treturn nil\n}\n\n// setOriginal 设置原创声明\nfunc setOriginal(page *rod.Page) error {\n\t// 根据小红书创作者页面的实际结构：\n\t// div.custom-switch-card 包含 span.has-tips 文本为\"原创声明\"\n\t// 开关是 div.d-switch 组件\n\n\t// 查找包含\"原创声明\"文本的 custom-switch-card\n\tswitchCards, err := page.Elements(\"div.custom-switch-card\")\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"查找原创声明卡片失败\")\n\t}\n","sourceCodeStart":947,"sourceCodeEnd":983,"githubUrl":"https://github.com/xpzouying/xiaohongshu-mcp/blob/332d196854a9eac0d2b8c2c0e3d0cc43139d724c/xiaohongshu/publish.go#L947-L983","documentation":"Thrown by setDateTime when humanize.Type fails to type the formatted datetime string into the input. Humanized typing simulates keystrokes; it fails if the element detaches mid-typing, focus is stolen, ctx is cancelled, or the page closes.","triggerScenarios":"A popup calendar steals focus mid-typing; the picker re-renders as characters are typed; ctx deadline expired; the input rejects synthetic key events after an XHS front-end change.","commonSituations":"Slow environments where typing outlasts a re-render; automation runs with a short-lived context; XHS input validation closing the picker on invalid intermediate values.","solutions":["Re-acquire the element and retry the full SelectAllText + Type sequence once.","Ensure ctx has an adequate deadline for the typing duration.","Dismiss any popup calendar overlaying the input before typing.","Verify the input still accepts keyboard events on the live XHS page; update the typing strategy if the component changed."],"exampleFix":"// before\nif err := humanize.Type(ctx, elem, dateTimeStr); err != nil {\n\treturn errors.Wrap(err, \"输入日期时间失败\")\n}\n// after\nif err := humanize.Type(ctx, elem, dateTimeStr); err != nil {\n\telem, err = page.Element(\".date-picker-container input\")\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"查找日期时间输入框失败\")\n\t}\n\t_ = elem.SelectAllText()\n\tif err := humanize.Type(ctx, elem, dateTimeStr); err != nil {\n\t\treturn errors.Wrap(err, \"输入日期时间失败\")\n\t}\n}","handlingStrategy":"try-catch","validationCode":"ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)\ndefer cancel()","typeGuard":null,"tryCatchPattern":"if err := setSchedulePublish(ctx, page, t); err != nil {\n\tif errors.Is(err, context.DeadlineExceeded) || strings.Contains(err.Error(), \"输入日期时间失败\") {\n\t\tslog.Warn(\"datetime typing failed, retrying once\")\n\t\treturn setSchedulePublish(ctx, page, t)\n\t}\n\treturn err\n}","preventionTips":["Give the typing context enough deadline for the full keystroke simulation.","Close calendar popups that may steal focus before typing.","Verify the field value after typing (elem.Text() or Eval on .value) to confirm success.","Keep the picker panel stable — avoid clicking elsewhere between select and type."],"tags":["type-input-failed","go-rod","automation","focus"],"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"}