{"record":{"id":"824f82ead9274dbc","repo":"xpzouying/xiaohongshu-mcp","slug":"error-824f82","errorCode":null,"errorMessage":"查找原创声明卡片失败","messagePattern":"查找原创声明卡片失败","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"xiaohongshu/publish.go","lineNumber":981,"sourceCode":"\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\n\tfor _, card := range switchCards {\n\t\ttext, err := card.Text()\n\t\tif err != nil {\n\t\t\tcontinue\n\t\t}\n\n\t\t// 检查是否是原创声明卡片\n\t\tif !strings.Contains(text, \"原创声明\") {\n\t\t\tcontinue\n\t\t}\n\n\t\t// 找到原创声明卡片，查找其中的 d-switch\n\t\tswitchElem, err := card.Element(\"div.d-switch\")\n\t\tif err != nil {\n\t\t\tcontinue\n\t\t}","sourceCodeStart":963,"sourceCodeEnd":999,"githubUrl":"https://github.com/xpzouying/xiaohongshu-mcp/blob/332d196854a9eac0d2b8c2c0e3d0cc43139d724c/xiaohongshu/publish.go#L963-L999","documentation":"Thrown by setOriginal when page.Elements(\"div.custom-switch-card\") fails to list the settings cards, meaning no div.custom-switch-card existed on the page — the publish settings section did not render or its markup changed.","triggerScenarios":"Calling submitPublish before the settings panel rendered; XHS renamed custom-switch-card after a front-end update; the page is on the wrong step of the publish wizard.","commonSituations":"XHS A/B redesign; the publish page still uploading media so settings cards appear late; an earlier automation step failed silently leaving the flow on a different panel.","solutions":["Wait for the settings section to render before setOriginal (Wait on div.custom-switch-card).","Dump page.HTML() on failure and update the selector if the class name changed.","Ensure prior publish steps (media upload, title) completed so the settings panel exists.","Increase the Elements timeout on slow networks."],"exampleFix":"// before\nswitchCards, err := page.Elements(\"div.custom-switch-card\")\n// after\nif err := page.Wait(\"() => !!document.querySelector('div.custom-switch-card')\"); err != nil {\n\treturn errors.Wrap(err, \"发布设置面板未渲染\")\n}\nswitchCards, err := page.Elements(\"div.custom-switch-card\")","handlingStrategy":"validation","validationCode":"if err := page.Wait(\"() => !!document.querySelector('div.custom-switch-card')\"); err != nil {\n\treturn fmt.Errorf(\"发布设置面板未渲染: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := setOriginal(page); err != nil {\n\tif strings.Contains(err.Error(), \"查找原创声明卡片失败\") {\n\t\thtml, _ := page.HTML()\n\t\tslog.Warn(\"switch cards missing\", \"htmlLen\", len(html))\n\t}\n\treturn err\n}","preventionTips":["Ensure media upload and prior steps completed before touching the settings panel.","Wait for the settings cards to exist instead of fixed sleeps.","Update selectors promptly when XHS ships front-end changes; track with a selector-verification test.","Handle late-appearing panels on slow networks with longer waits."],"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-14T00:17:10.932Z"}