xpzouying/xiaohongshu-mcp · error
未找到声明原创按钮
Error message
未找到声明原创按钮
What it means
Thrown by confirmOriginalDeclaration when footer.Element("button.custom-button") fails — the 声明原创 dialog footer was found but contains no button.custom-button. The dialog is present but its internal button markup does not match, or the matched footer belongs to a different dialog.
Source
Thrown at xiaohongshu/publish.go:1054
func confirmOriginalDeclaration(page *rod.Page) error {
time.Sleep(800 * time.Millisecond) // 技术等待:等确认弹窗渲染
if footer, err := findFooterByText(page, "原创声明须知"); err != nil {
slog.Warn("未找到原创声明确认弹窗的 footer", "error", err)
} else if err := checkFooterCheckbox(footer); err != nil {
slog.Warn("勾选原创声明须知失败", "error", err)
}
time.Sleep(500 * time.Millisecond) // 技术等待:勾选后等"声明原创"按钮变可用
footer, err := findFooterByText(page, "声明原创")
if err != nil {
return errors.Wrap(err, "未找到声明原创弹窗")
}
btn, err := footer.Element("button.custom-button")
if err != nil {
return errors.Wrap(err, "未找到声明原创按钮")
}
if isButtonDisabled(btn) {
// 兜底:按钮仍禁用,可能须知未勾上,再勾一次
if err := checkFooterCheckbox(footer); err != nil {
slog.Warn("二次勾选须知失败", "error", err)
}
time.Sleep(300 * time.Millisecond)
if isButtonDisabled(btn) {
return errors.New("声明原创按钮仍处于禁用状态")
}
}
if err := humanize.Click(btn); err != nil {
return errors.Wrap(err, "点击声明原创按钮失败")
}
slog.Info("已成功点击声明原创按钮")
time.Sleep(300 * time.Millisecond)View on GitHub (pinned to 332d196854)
Solutions
- Inspect the live dialog DOM (page.HTML()) and update the button selector to current class names.
- Use a robust selector: footer.Elements("button") and pick by text content instead of a hard-coded class.
- Wait for the button to exist before querying instead of relying on fixed sleeps.
- Log the matched footer text to confirm findFooterByText found the intended dialog.
Example fix
// before
btn, err := footer.Element("button.custom-button")
// after
btns, err := footer.Elements("button")
if err != nil {
return errors.Wrap(err, "未找到声明原创按钮")
}
var btn *rod.Element
for _, b := range btns {
t, _ := b.Text()
if strings.Contains(t, "声明原创") {
btn = b
break
}
}
if btn == nil {
return errors.New("未找到声明原创按钮")
} Defensive patterns
Strategy: fallback
Validate before calling
ok, err := page.Eval(`() => { const f=[...document.querySelectorAll('div.footer')].find(x=>x.innerText.includes('声明原创')); return !!f && !!f.querySelector('button'); }`)
if err != nil || !ok.Value.Bool() {
return fmt.Errorf("声明原创弹窗内未找到按钮")
} Try / catch
if err := setOriginal(page); err != nil {
if strings.Contains(err.Error(), "未找到声明原创按钮") {
html, _ := page.HTML()
slog.Warn("confirm button selector mismatch", "htmlLen", len(html))
}
return err
} Prevention
- Select buttons by visible text rather than hard-coded class names like custom-button.
- Log the matched footer's text to confirm findFooterByText found the right dialog.
- Re-verify selectors after each XHS front-end release.
- Wait for the dialog to finish rendering before querying its buttons.
When it happens
Trigger: XHS changed the confirm button's class away from custom-button; findFooterByText matched a different dialog whose footer contains 声明原创 text but no such button; the dialog is mid-render so the button has not mounted yet.
Common situations: XHS front-end update renaming button classes; multiple stacked dialogs; slow dialog render outpacing the fixed sleeps.
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/9e511320ca12c650.
Report an issue: GitHub.