xpzouying/xiaohongshu-mcp · error

无法点击提交按钮: %w

Error message

无法点击提交按钮: %w

What it means

PostComment 找到提交按钮后 humanize.Click 模拟点击失败:按钮被浮层遮挡、处于禁用态或页面在点击瞬间重渲染导致坐标失效。

Source

Thrown at xiaohongshu/comment_feed.go:74

		return fmt.Errorf("未找到评论输入区域: %w", err)
	}

	if err := humanize.Type(ctx, elem2, content); err != nil {
		logrus.Warnf("Failed to input comment content: %v", err)
		return fmt.Errorf("无法输入评论内容: %w", err)
	}

	humanize.Delay(ctx, humanize.AfterType)

	submitButton, err := page.Element("div.bottom button.submit")
	if err != nil {
		logrus.Warnf("Failed to find submit button: %v", err)
		return fmt.Errorf("未找到提交按钮: %w", err)
	}

	if err := humanize.Click(submitButton); err != nil {
		logrus.Warnf("Failed to click submit button: %v", err)
		return fmt.Errorf("无法点击提交按钮: %w", err)
	}

	humanize.Delay(ctx, humanize.AfterClick)

	// 就地校验:提交后评论应在评论区渲染出现;未出现则判定失败,避免假成功。
	if !waitCommentRendered(page, content, 4*time.Second) {
		logrus.Warnf("评论提交后未在评论区渲染,判定未成功: feed=%s", feedID)
		return fmt.Errorf("评论未确认成功:提交后未在评论区出现(可能账号被限制或发送失败),feed: %s", feedID)
	}

	logrus.Infof("Comment posted and verified to feed: %s", feedID)
	return nil
}

// commentRendered 就地读当前页评论区 DOM,判断指定文本的评论是否已渲染出现。
// 不重新导航、不滚动——只读已加载的 .comments-container 的可见文本。
func commentRendered(page *rod.Page, content string) bool {
	res, err := page.Eval(`(txt) => {

View on GitHub (pinned to 332d196854)

Solutions

  1. Retry PostComment once after a delay; transient overlay/staleness often clears
  2. Wait for page stability before submitting (no pending network/animations)
  3. Check for and dismiss any popup/captcha before clicking
  4. Re-verify selectors in case the button node is replaced on re-render

Example fix

// before
err := svc.PostComment(ctx, feedID, content) // single attempt
// after
if err := svc.PostComment(ctx, feedID, content); err != nil {
    time.Sleep(3 * time.Second)
    err = svc.PostComment(ctx, feedID, content)
}
Defensive patterns

Strategy: retry

Validate before calling

// 点击前等待无弹窗、页面稳定
page.MustWaitStable()
// 若可注入:确认无遮罩层元素覆盖提交按钮

Try / catch

var err error
for i := 0; i < 3; i++ {
    if err = svc.PostComment(ctx, feedID, content); err == nil || !strings.Contains(err.Error(), "无法点击提交按钮") {
        break
    }
    time.Sleep(3 * time.Second)
}

Prevention

When it happens

Trigger: humanize.Click on the submit button fails because the editor re-rendered and replaced the button node, a toast/overlay covers it, or the page started navigating on Enter.

Common situations: Client-side validation clearing the editor right before submit; anti-bot challenge popping up; slow hydration causing stale element reference; duplicate rapid calls.

Related errors


AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05). Data as JSON: /api/errors/29c8e279471bbcb1. Report an issue: GitHub.