xpzouying/xiaohongshu-mcp · error

无法点击评论输入框: %w

Error message

无法点击评论输入框: %w

What it means

After finding the comment box, PostComment clicks it via humanize.Click to focus the editor. If the click fails (element detached, intercepted by overlay, page navigating), this wrapped error is returned.

Source

Thrown at xiaohongshu/comment_feed.go:49

	// 导航到详情页
	page.MustNavigate(url)
	page.MustWaitDOMStable()
	humanize.Delay(ctx, humanize.AfterNavigate)

	// 检测页面是否可访问
	if err := checkPageAccessible(page); err != nil {
		return err
	}

	elem, err := page.Element("div.input-box div.content-edit span")
	if err != nil {
		logrus.Warnf("Failed to find comment input box: %v", err)
		return fmt.Errorf("未找到评论输入框,该帖子可能不支持评论或网页端不可访问: %w", err)
	}

	if err := humanize.Click(elem); err != nil {
		logrus.Warnf("Failed to click comment input box: %v", err)
		return fmt.Errorf("无法点击评论输入框: %w", err)
	}
	humanize.Delay(ctx, humanize.AfterClick)

	elem2, err := page.Element("div.input-box div.content-edit p.content-input")
	if err != nil {
		logrus.Warnf("Failed to find comment input field: %v", err)
		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 {

View on GitHub (pinned to 332d196854)

Solutions

  1. Retry the whole PostComment operation once after a short delay
  2. Ensure the page is fully loaded/idle before calling PostComment (wait for network idle)
  3. Re-authenticate if a login modal is intercepting clicks
  4. Extend humanize/page timeouts if the environment is slow

Example fix

// before
_ = svc.PostComment(ctx, feedID, content) // no retry
// after
err := svc.PostComment(ctx, feedID, content)
if 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 < 2; 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 comment input span fails because the page navigated/reloaded, a modal/login popup covers the element, or the element became stale between lookup and click.

Common situations: Slow networks where the page is still hydrating; login-expired popups stealing the click; anti-bot overlays; rapid successive calls reusing a closing page.

Related errors


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