xpzouying/xiaohongshu-mcp · error

点击标签联想选项失败

Error message

点击标签联想选项失败

What it means

inputTag wraps failure from humanize.Click on the first topic-autocomplete item. The dropdown appeared and an option was found, but clicking it failed. This means the automation could not complete the tag selection click on the suggestion item.

Source

Thrown at xiaohongshu/publish.go:751

	}

	time.Sleep(1 * time.Second) // 技术等待:等联想结果刷新

	page := contentElem.Page()
	topicContainer, err := page.Element("#creator-editor-topic-container")
	if err != nil || topicContainer == nil {
		slog.Warn("未找到标签联想下拉框,直接输入空格", "tag", tag)
		return humanize.Type(ctx, contentElem, " ")
	}

	firstItem, err := topicContainer.Element(".item")
	if err != nil || firstItem == nil {
		slog.Warn("未找到标签联想选项,直接输入空格", "tag", tag)
		return humanize.Type(ctx, contentElem, " ")
	}

	if err := humanize.Click(firstItem); err != nil {
		return errors.Wrap(err, "点击标签联想选项失败")
	}
	slog.Info("成功点击标签联想选项", "tag", tag)
	time.Sleep(500 * time.Millisecond) // 技术等待:等标签处理完成
	return nil
}

func findTextboxByPlaceholder(page *rod.Page) (*rod.Element, error) {
	elements, err := page.Elements("p")
	if err != nil {
		return nil, errors.Wrap(err, "查找正文候选元素失败")
	}
	if len(elements) == 0 {
		return nil, errors.New("no p elements found")
	}

	placeholderElem := findPlaceholderElement(elements, "输入正文描述")
	if placeholderElem == nil {
		return nil, errors.New("no placeholder element found")

View on GitHub (pinned to 332d196854)

Solutions

  1. Call WaitStable on firstItem before humanize.Click.
  2. Increase the post-'#' wait (currently 1s) before locating the option.
  3. Fall back to typing a space (the code already does this when no option is found) — wrap the whole flow with a retry that does that fallback on click failure too.
  4. Re-query the option element immediately before clicking.

Example fix

// before
if err := humanize.Click(firstItem); err != nil {
    return errors.Wrap(err, "点击标签联想选项失败")
}
// after
if err := firstItem.WaitStable(200 * time.Millisecond); err == nil {
    if err := humanize.Click(firstItem); err != nil {
        return humanize.Type(ctx, contentElem, " ") // 降级:直接输入空格结束标签
    }
}
Defensive patterns

Strategy: fallback

Validate before calling

if err := firstItem.WaitStable(200 * time.Millisecond); err != nil { firstItem = nil } // 视为未找到,走空格降级

Type guard

func clickable(e *rod.Element) bool { return e != nil && e.WaitStable(200*time.Millisecond) == nil }

Try / catch

if err := humanize.Click(firstItem); err != nil {
    slog.Warn("点击联想选项失败,输入空格降级", "tag", tag)
    return humanize.Type(ctx, contentElem, " ")
}

Prevention

When it happens

Trigger: The suggestion item was found but detached/re-rendered before the click landed; the click was intercepted by an overlay; CDP click timed out; the dropdown closed between element search and click.

Common situations: Slow network to the browser causing the 1s autocomplete refresh window to be insufficient; UI A/B changes move or re-render the topic container; concurrent automation on the same page steals focus.

Related errors


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