xpzouying/xiaohongshu-mcp · error

未找到提交按钮: %w

Error message

未找到提交按钮: %w

What it means

PostComment 评论内容输入完成后,用 div.bottom button.submit 选择器查找提交按钮失败:按钮未渲染(输入校验未通过、内容为空被前端禁用)或页面结构变化。

Source

Thrown at xiaohongshu/comment_feed.go:69

	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 {
		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
}

View on GitHub (pinned to 332d196854)

Solutions

  1. Inspect live DOM and update the 'div.bottom button.submit' selector to current markup
  2. Ensure the editor still has focus before looking for the submit button
  3. Wait for the button element with a timeout instead of immediate query
  4. Verify account/comment permissions in a normal browser session

Example fix

// before
submitButton, err := page.Element("div.bottom button.submit")
// after
submitButton, err := page.Element("div.bottom button.submit", rod.El{"timeout": 5 * time.Second}) // and confirm selector against current DOM
Defensive patterns

Strategy: try-catch

Validate before calling

// 提交前确认按钮存在于当前 DOM(页面稳定后)
page.MustWaitStable()
_ = page.MustElement("div.bottom button.submit")

Try / catch

err := svc.PostComment(ctx, feedID, content)
if err != nil && strings.Contains(err.Error(), "未找到提交按钮") {
    // 检查是否改版/编辑器收起,人工核对后更新选择器
    log.Warnf("提交按钮未找到: %v", err)
}

Prevention

When it happens

Trigger: The submit button is absent because the editor closed, the XHS UI renamed/removed button.submit, or the page rendered an alternate layout (mobile/AB test) without that class.

Common situations: XHS frontend redesign changing button classes; editor auto-collapsed after typing due to lost focus; account-restricted state hiding the submit control; half-loaded page.

Related errors


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