{"record":{"id":"1056426cd27e0079","repo":"xpzouying/xiaohongshu-mcp","slug":"error-105642","errorCode":null,"errorMessage":"查找正文输入框失败","messagePattern":"查找正文输入框失败","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"xiaohongshu/publish.go","lineNumber":664,"sourceCode":"// contentElemSelectors 正文输入框的候选选择器，按先后顺序尝试。\nvar contentElemSelectors = []string{\n\t`div[role=\"textbox\"][contenteditable=\"true\"]`,\n\t`div.tiptap[contenteditable=\"true\"]`,\n\t`div.ql-editor`,\n}\n\n// getContentElement 在 timeout 内轮询查找正文输入框，全部落空返回错误。\nfunc getContentElement(page *rod.Page, timeout time.Duration) (*rod.Element, error) {\n\tdeadline := time.Now().Add(timeout)\n\n\tfor {\n\t\telem, err := findContentElement(page)\n\t\tif err == nil {\n\t\t\treturn elem, nil\n\t\t}\n\n\t\tif time.Now().After(deadline) {\n\t\t\treturn nil, errors.Wrap(err, \"查找正文输入框失败\")\n\t\t}\n\t\ttime.Sleep(300 * time.Millisecond)\n\t}\n}\n\nfunc findContentElement(page *rod.Page) (*rod.Element, error) {\n\tfor _, selector := range contentElemSelectors {\n\t\telems, err := page.Elements(selector)\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrapf(err, \"查找正文输入框失败: %s\", selector)\n\t\t}\n\n\t\tfor _, elem := range elems {\n\t\t\tif isElementVisible(elem) {\n\t\t\t\treturn elem, nil\n\t\t\t}\n\t\t}\n\t}","sourceCodeStart":646,"sourceCodeEnd":682,"githubUrl":"https://github.com/xpzouying/xiaohongshu-mcp/blob/332d196854a9eac0d2b8c2c0e3d0cc43139d724c/xiaohongshu/publish.go#L646-L682","documentation":"This error is returned by getContentElement after it repeatedly failed to find a visible body content input element within the given timeout. It wraps the last error from findContentElement, meaning none of the candidate CSS selectors (role=textbox, .tiptap, .ql-editor) matched a visible element before the deadline. The publish flow cannot continue without the content editor element.","triggerScenarios":"submitPublish or submitPublishVideo calls getContentElement(page, timeout); every poll of findContentElement either errors on page.Elements or finds no visible element, and the deadline expires — the error wraps the last failure.","commonSituations":"Publish page not fully loaded or showing a different editor variant; Xiaohongshu updated its editor DOM so selectors no longer match; editor is inside an iframe not being searched; page failed to load due to network/login issues.","solutions":["Increase the timeout passed to getContentElement if the page loads slowly.","Verify the publish page actually loaded the editor (check login state, page URL, screenshots).","Update contentElemSelectors in xiaohongshu/publish.go if the site DOM changed (inspect the live editor).","Check whether the editor lives in an iframe and extend search to iframe pages."],"exampleFix":"// before\nelem, err := getContentElement(page, 5*time.Second)\n// after\nelem, err := getContentElement(page, 30*time.Second) // allow slow editor load","handlingStrategy":"retry","validationCode":"// verify the editor actually rendered before publishing\ntime.Sleep(3 * time.Second) // or wait for a page-load signal\nif has, _, _ := page.Has(`div[role=\"textbox\"][contenteditable=\"true\"]`); !has {\n    return errors.New(\"编辑器未加载，取消发布\")\n}","typeGuard":"func contentEditorVisible(page *rod.Page) bool {\n    for _, sel := range []string{\n        `div[role=\"textbox\"][contenteditable=\"true\"]`,\n        `div.tiptap[contenteditable=\"true\"]`,\n        `div.ql-editor`,\n    } {\n        if has, _, _ := page.Has(sel); has {\n            return true\n        }\n    }\n    return false\n}","tryCatchPattern":"err := publisher.Publish(ctx, opts)\nif err != nil && strings.Contains(err.Error(), \"查找正文输入框失败\") {\n    // editor never appeared: reload the publish page and retry once\n    page.Reload()\n    err = publisher.Publish(ctx, opts)\n}","preventionTips":["Use a generous timeout for editor load on slow networks","Confirm login state and correct publish URL before starting","Screenshot the page on failure to diagnose missing editor","Update selectors after site front-end updates"],"tags":["dom","selector","timeout","browser-automation","xiaohongshu"],"backgroundTag":"element-not-found-timeout","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"}