xpzouying/xiaohongshu-mcp · error
页面没有文件上传输入框
Error message
页面没有文件上传输入框
What it means
This error is thrown by findImageUploadInput when the Xiaohongshu publish page DOM contains no `input[type="file"]` elements. The library relies on a native file input to call rod's SetFiles for image uploads; without such an input it cannot proceed. It typically means the page did not load into the expected upload state or XHS changed its upload widget markup.
Source
Thrown at xiaohongshu/publish.go:283
}
time.Sleep(1 * time.Second)
}
return nil
}
// findImageUploadInput 查找图片上传的输入框
func findImageUploadInput(page *rod.Page, first bool) (*rod.Element, error) {
if first {
return page.Element(".upload-input")
}
inputs, err := page.Elements(`input[type="file"]`)
if err != nil {
return nil, err
}
if len(inputs) == 0 {
return nil, errors.New("页面没有文件上传输入框")
}
for _, input := range inputs {
accept, err := input.Attribute("accept")
if err != nil || accept == nil {
continue
}
if acceptsImage(*accept) {
return input, nil
}
}
return inputs[0], nil
}
// acceptsImage 判断 accept 属性是否接受图片
func acceptsImage(accept string) bool {
accept = strings.ToLower(accept)View on GitHub (pinned to 332d196854)
Solutions
- Verify the browser is still on the image publish page (URL contains /publish/publish) before calling uploadImages
- Increase wait for the page/upload widget to render before the first upload (wait for `.upload-input` or the upload area to appear)
- Check if Xiaohongshu changed the DOM; update the `input[type="file"]` selector in findImageUploadInput accordingly
- Retry uploadImages; transient rendering races often resolve on a second run
Example fix
// before
if len(inputs) == 0 {
return nil, errors.New("页面没有文件上传输入框")
}
// after
if len(inputs) == 0 {
// wait briefly for lazy-rendered input
_ = page.WaitElementsMoreThan(`input[type="file"]`, 0, 5*time.Second) // or fallback to .upload-input
} Defensive patterns
Strategy: retry
Validate before calling
func hasFileInput(page *rod.Page) bool {
inputs, err := page.Elements(`input[type="file"]`)
return err == nil && len(inputs) > 0
} Try / catch
for attempt := 0; attempt < 3; attempt++ {
if err := uploadImages(page, paths); err == nil {
break
} else if strings.Contains(err.Error(), "页面没有文件上传输入框") {
time.Sleep(3 * time.Second) // 等页面渲染后重试
continue
}
return err
} Prevention
- Before uploading, wait for the upload widget (.upload-input) to be visible
- Confirm the page URL is still the publish page before each image upload step
- Re-check XHS DOM selectors after frontend updates
When it happens
Trigger: uploadImages calls findImageUploadInput for the 2nd..Nth image (first image uses `.upload-input`); the selector `input[type="file"]` matches zero elements — e.g. page still loading, previous upload navigated away, or the DOM was re-rendered removing the hidden input.
Common situations: Slow network leaving the publish page half-rendered; XHS frontend update that lazy-creates the file input only after a click; calling uploadImages after the page already navigated; a modal/overlay replacing the upload area mid-loop.
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/8c1894359875bb5b.
Report an issue: GitHub.