xpzouying/xiaohongshu-mcp · error

输入标题失败

Error message

输入标题失败

What it means

After finding the title element, submitPublishVideo types the title via humanize.Type (simulated human keystrokes). If that returns an error it is wrapped as "输入标题失败". Typically the element became stale/detached or the context was cancelled mid-typing.

Source

Thrown at xiaohongshu/publish_video.go:111

	// 对于视频,等待发布按钮变为可点击即表示处理完成
	btn, err := waitForPublishButtonClickable(pp, 10*time.Minute)
	if err != nil {
		return err
	}
	slog.Info("视频上传/处理完成,发布按钮可点击", "btn", btn)
	return nil
}

// submitPublishVideo 填写标题、正文、标签并点击发布(等待按钮可点击后再提交)
func submitPublishVideo(ctx context.Context, page *rod.Page, title, content string, tags []string, scheduleTime *time.Time, 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)

	// 正文 + 标签
	contentElem, err := getContentElement(page, contentElemTimeout)
	if err != nil {
		return err
	}
	if err := humanize.Type(ctx, contentElem, content); err != nil {
		return errors.Wrap(err, "输入正文失败")
	}
	if err := waitAndClickTitleInput(titleElem); err != nil {
		return err
	}
	if err := inputTags(ctx, contentElem, tags); err != nil {
		return err
	}

View on GitHub (pinned to 332d196854)

Solutions

  1. Re-lookup the element immediately before typing, or wrap typing in a retry that re-finds the element
  2. Extend the context deadline to allow for human-paced typing
  3. Ensure no overlay/dialog intercepts input — dismiss popups first
  4. Validate title length/content before calling

Example fix

// before
if err := humanize.Type(ctx, titleElem, title); err != nil {
    return errors.Wrap(err, "输入标题失败")
}
// after
for i := 0; i < 2; i++ {
    titleElem, err = page.Element("div.d-input input")
    if err == nil && humanize.Type(ctx, titleElem, title) == nil {
        break
    }
}
Defensive patterns

Strategy: retry

Validate before calling

if visible, err := titleElem.Visible(); err != nil || !visible {
    return errors.New("title input not visible for typing")
}

Try / catch

if err := humanize.Type(ctx, titleElem, title); err != nil {
    titleElem, ferr := page.Element("div.d-input input") // re-find stale element
    if ferr != nil { return ferr }
    if terr := humanize.Type(ctx, titleElem, title); terr != nil {
        return errors.Wrap(terr, "输入标题失败")
    }
}

Prevention

When it happens

Trigger: humanize.Type(ctx, titleElem, title) fails because the element was removed/re-rendered between lookup and typing, ctx deadline exceeded, or the underlying rod input events error out (element not visible, page navigated).

Common situations: Page re-renders the editor right after element lookup (auto-focus redraw); ctx timeout too short for human-speed typing of a long title; modal (e.g. login prompt) steals focus; empty or oversized title rejected by an inline handler.

Related errors


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