{"record":{"id":"d9e16fdffe86a8de","repo":"xpzouying/xiaohongshu-mcp","slug":"error-d9e16f","errorCode":null,"errorMessage":"查找正文候选元素失败","messagePattern":"查找正文候选元素失败","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"xiaohongshu/publish.go","lineNumber":761,"sourceCode":"\n\tfirstItem, err := topicContainer.Element(\".item\")\n\tif err != nil || firstItem == nil {\n\t\tslog.Warn(\"未找到标签联想选项，直接输入空格\", \"tag\", tag)\n\t\treturn humanize.Type(ctx, contentElem, \" \")\n\t}\n\n\tif err := humanize.Click(firstItem); err != nil {\n\t\treturn errors.Wrap(err, \"点击标签联想选项失败\")\n\t}\n\tslog.Info(\"成功点击标签联想选项\", \"tag\", tag)\n\ttime.Sleep(500 * time.Millisecond) // 技术等待：等标签处理完成\n\treturn nil\n}\n\nfunc findTextboxByPlaceholder(page *rod.Page) (*rod.Element, error) {\n\telements, err := page.Elements(\"p\")\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"查找正文候选元素失败\")\n\t}\n\tif len(elements) == 0 {\n\t\treturn nil, errors.New(\"no p elements found\")\n\t}\n\n\tplaceholderElem := findPlaceholderElement(elements, \"输入正文描述\")\n\tif placeholderElem == nil {\n\t\treturn nil, errors.New(\"no placeholder element found\")\n\t}\n\n\ttextboxElem := findTextboxParent(placeholderElem)\n\tif textboxElem == nil {\n\t\treturn nil, errors.New(\"no textbox parent found\")\n\t}\n\n\treturn textboxElem, nil\n}\n","sourceCodeStart":743,"sourceCodeEnd":779,"githubUrl":"https://github.com/xpzouying/xiaohongshu-mcp/blob/332d196854a9eac0d2b8c2c0e3d0cc43139d724c/xiaohongshu/publish.go#L743-L779","documentation":"findTextboxByPlaceholder wraps failure from page.Elements(\"p\") when enumerating candidate content paragraphs. This error means rod could not execute the query for <p> elements on the publish page, typically a CDP-level failure rather than 'no elements found' (that returns a separate error).","triggerScenarios":"Calling findContentElement when the page object is invalid, the tab was closed, the CDP connection dropped, or page.Elements hit a navigation/race while querying.","commonSituations":"Browser closed mid-flow; page navigated between publish steps; remote browser endpoint unreachable; using a stale rod.Page after the tab crashed.","solutions":["Verify the page is alive before searching (e.g., page.Info() or page.MustWaitStable pattern).","Re-navigate/reload the publish page if the session is stale, then retry.","Check the rod browser connection and re-connect if the CDP websocket dropped.","Wrap with a short retry since transient CDP races are common."],"exampleFix":"// before\nelements, err := page.Elements(\"p\")\n// after\nif _, err := page.Info(); err != nil {\n    return nil, errors.Wrap(err, \"页面已失效，请重新打开发布页\")\n}\nelements, err := page.Elements(\"p\")","handlingStrategy":"try-catch","validationCode":"if _, err := page.Info(); err != nil { return errors.Wrap(err, \"页面已失效\") }","typeGuard":"func pageAlive(p *rod.Page) bool { _, err := p.Info(); return err == nil }","tryCatchPattern":"contentElem, err := findContentElement(page)\nif err != nil {\n    if strings.Contains(err.Error(), \"查找正文候选元素失败\") {\n        return errors.New(\"发布页不可用，请重新打开后再试\")\n    }\n    return err\n}","preventionTips":["Check page liveness before DOM queries","Reopen the publish page after navigation","Handle browser disconnects at the session level"],"tags":["browser-automation","rod","dom-query"],"backgroundTag":"cdp-element-query-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"}