xpzouying/xiaohongshu-mcp · error

查找标题输入框失败

Error message

查找标题输入框失败

What it means

submitPublish locates the post title field with page.Element("div.d-input input") using rod's default timeout. If the selector matches no element before timing out, the rod error is wrapped as '查找标题输入框失败'. This almost always means the publish page did not render the expected title input, or the site's markup changed.

Source

Thrown at xiaohongshu/publish.go:347

		if currentCount != lastLogCount {
			slog.Info("等待图片上传", "current", currentCount, "expected", expectedCount)
			lastLogCount = currentCount
		}
		if currentCount >= expectedCount {
			slog.Info("图片上传完成", "count", currentCount)
			return nil
		}

		time.Sleep(checkInterval)
	}

	return errors.Errorf("第%d张图片上传超时(60s),请检查网络连接和图片大小", expectedCount)
}

func submitPublish(ctx context.Context, page *rod.Page, title, content string, tags []string, scheduleTime *time.Time, isOriginal bool, visibility string, products []string) error {
	titleElem, err := page.Element("div.d-input input")
	if err != nil {
		return errors.Wrap(err, "查找标题输入框失败")
	}
	if err := humanize.Type(ctx, titleElem, title); err != nil {
		return errors.Wrap(err, "输入标题失败")
	}

	humanize.Delay(ctx, humanize.AfterType)
	if err := checkTitleMaxLength(page); err != nil {
		return err
	}
	slog.Info("检查标题长度:通过")

	humanize.Delay(ctx, humanize.AfterType)

	contentElem, err := getContentElement(page, contentElemTimeout)
	if err != nil {
		return err
	}
	if err := humanize.Type(ctx, contentElem, content); err != nil {

View on GitHub (pinned to 332d196854)

Solutions

  1. Verify the login session is valid and the creator publish page actually loaded (screenshot the page on failure)
  2. Open the publish page and inspect the title input; if markup changed, update the selector 'div.d-input input'
  3. Ensure the correct publish tab (图文) is active before submitPublish runs
  4. Add a longer/explicit timeout or wait for page stability before querying the element

Example fix

// before
titleElem, err := page.Element("div.d-input input")
// after
titleElem, err := page.Timeout(30 * time.Second).Element("div.d-input input") // 或更新为站点新选择器
Defensive patterns

Strategy: try-catch

Validate before calling

// 调用前确认登录态与发布页可达
if !bot.IsLoggedIn(ctx) { return errors.New("登录已过期") }

Try / catch

err := bot.Publish(ctx, post, images)
if err != nil && strings.Contains(err.Error(), "查找标题输入框失败") {
    // 截图排查: 登录态/页面跳转/选择器过期
}

Prevention

When it happens

Trigger: Publish → submitPublish where page.Element("div.d-input input") times out because no title input exists on the page (xiaohongshu/publish.go:347).

Common situations: Not logged in or session expired so the creator page redirected; the publish page failed to load fully; Xiaohongshu changed the title input markup away from div.d-input; navigating to the wrong page type (e.g. video publish tab with a different form).

Related errors


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