xpzouying/xiaohongshu-mcp · error

查找商品按钮文本失败

Error message

查找商品按钮文本失败

What it means

clickAddProductButton wraps page.Elements("span.d-text") failure with this message. The bulk selector query itself errored (page gone, context canceled, CDP failure) before any text matching could happen. Note this is distinct from the wrapped '点击添加商品按钮失败' (error 215) which reports the outcome when no matching span or clickable parent is found.

Source

Thrown at xiaohongshu/publish.go:1186

	}

	if len(failedProducts) > 0 {
		return errors.Errorf("部分商品未找到: %v", failedProducts)
	}

	slog.Info("商品绑定完成", "total", len(products))
	time.Sleep(1000 * time.Millisecond)
	return nil
}

// clickAddProductButton 点击"添加商品"按钮
func clickAddProductButton(page *rod.Page) error {
	slog.Info("开始查找添加商品按钮")

	// 查找包含"添加商品"文本的元素
	spans, err := page.Elements("span.d-text")
	if err != nil {
		return errors.Wrap(err, "查找商品按钮文本失败")
	}

	for _, span := range spans {
		text, err := span.Text()
		if err != nil {
			continue
		}
		if strings.TrimSpace(text) == "添加商品" {
			slog.Info("找到添加商品文本,向上查找可点击父元素")
			// 向上查找可点击的父元素
			parent := span
			for i := 0; i < 5; i++ {
				p, err := parent.Parent()
				if err != nil {
					break
				}
				parent = p

View on GitHub (pinned to 332d196854)

Solutions

  1. Ensure the publish page is loaded and alive before binding products
  2. Check the wrapped inner error for the underlying rod/CDP cause
  3. Increase or fix context deadlines around the publish flow
  4. Re-navigate and retry the publish step
Defensive patterns

Strategy: try-catch

Validate before calling

if page == nil { return errors.New("page is nil") }
if _, err := page.Info(); err != nil { return fmt.Errorf("page not alive: %w", err) }

Try / catch

if err := bindProducts(ctx, page, products); err != nil {
    if strings.Contains(err.Error(), "查找商品按钮文本失败") {
        // page context lost: re-navigate and retry once
    }
}

Prevention

When it happens

Trigger: page.Elements("span.d-text") fails because the tab was closed/navigated, the rod context expired, or the CDP session dropped during the query.

Common situations: Calling bindProducts after the page navigated or browser crashed; a canceled context (deadline) killing the evaluation; reconnect issues with a remote browser.

Related errors


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