xpzouying/xiaohongshu-mcp · error
no p elements found
Error message
no p elements found
What it means
findTextboxByPlaceholder enumerates all `<p>` elements looking for the description placeholder ('输入正文描述'). If the page has zero `p` elements at query time, it throws 'no p elements found'. This means the content editor area has not rendered at all, or XHS changed its editor markup away from `<p>`-based (ProseMirror/Quill) placeholders.
Source
Thrown at xiaohongshu/publish.go:764
slog.Warn("未找到标签联想选项,直接输入空格", "tag", tag)
return humanize.Type(ctx, contentElem, " ")
}
if err := humanize.Click(firstItem); err != nil {
return errors.Wrap(err, "点击标签联想选项失败")
}
slog.Info("成功点击标签联想选项", "tag", tag)
time.Sleep(500 * time.Millisecond) // 技术等待:等标签处理完成
return nil
}
func findTextboxByPlaceholder(page *rod.Page) (*rod.Element, error) {
elements, err := page.Elements("p")
if err != nil {
return nil, errors.Wrap(err, "查找正文候选元素失败")
}
if len(elements) == 0 {
return nil, errors.New("no p elements found")
}
placeholderElem := findPlaceholderElement(elements, "输入正文描述")
if placeholderElem == nil {
return nil, errors.New("no placeholder element found")
}
textboxElem := findTextboxParent(placeholderElem)
if textboxElem == nil {
return nil, errors.New("no textbox parent found")
}
return textboxElem, nil
}
func findPlaceholderElement(elements []*rod.Element, searchText string) *rod.Element {
for _, elem := range elements {
placeholder, err := elem.Attribute("data-placeholder")View on GitHub (pinned to 332d196854)
Solutions
- Wait for the editor container to appear before calling findContentElement (e.g. page.Element on the editor wrapper with a timeout)
- Retry after a short sleep — editor may be mid-render
- If XHS changed the editor, update the selector (check for [contenteditable], textarea, or new placeholder text)
- Confirm the browser is actually on the publish page before filling content
Example fix
// before
elements, err := page.Elements("p")
if len(elements) == 0 {
return nil, errors.New("no p elements found")
}
// after
elements, err := page.Elements("p")
if len(elements) == 0 {
_ = page.WaitElementsMoreThan("p", 0, 5*time.Second) // 等编辑器渲染
elements, _ = page.Elements("p")
if len(elements) == 0 {
return nil, errors.New("no p elements found")
}
} Defensive patterns
Strategy: validation
Validate before calling
// 填正文前确认编辑器已渲染
if _, err := page.Element(".editor-container, [contenteditable='true']"); err != nil {
return errors.New("发布页编辑器尚未渲染,请稍候再填正文")
} Prevention
- Wait for the editor container to mount before filling the description
- Confirm the page is on /publish/publish before content steps
- After XHS frontend updates, re-verify that the description editor still uses <p> placeholder elements
When it happens
Trigger: findContentElement → findTextboxByPlaceholder runs page.Elements("p") on a page where the editor hasn't mounted yet (blank/half-loaded publish page) or where the description box is an iframe/textarea rather than p elements.
Common situations: Calling the content-fill step before the publish page finished loading; XHS redesign replacing the p-based rich editor; mobile vs desktop page variants with different editors; navigation happened before this step so the queried page is wrong.
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/90176ae1627aaa89.
Report an issue: GitHub.