{"record":{"id":"077302713c558a48","repo":"xpzouying/xiaohongshu-mcp","slug":"error-077302","errorCode":null,"errorMessage":"查找商品按钮文本失败","messagePattern":"查找商品按钮文本失败","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"xiaohongshu/publish.go","lineNumber":1186,"sourceCode":"\t}\n\n\tif len(failedProducts) > 0 {\n\t\treturn errors.Errorf(\"部分商品未找到: %v\", failedProducts)\n\t}\n\n\tslog.Info(\"商品绑定完成\", \"total\", len(products))\n\ttime.Sleep(1000 * time.Millisecond)\n\treturn nil\n}\n\n// clickAddProductButton 点击\"添加商品\"按钮\nfunc clickAddProductButton(page *rod.Page) error {\n\tslog.Info(\"开始查找添加商品按钮\")\n\n\t// 查找包含\"添加商品\"文本的元素\n\tspans, err := page.Elements(\"span.d-text\")\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"查找商品按钮文本失败\")\n\t}\n\n\tfor _, span := range spans {\n\t\ttext, err := span.Text()\n\t\tif err != nil {\n\t\t\tcontinue\n\t\t}\n\t\tif strings.TrimSpace(text) == \"添加商品\" {\n\t\t\tslog.Info(\"找到添加商品文本，向上查找可点击父元素\")\n\t\t\t// 向上查找可点击的父元素\n\t\t\tparent := span\n\t\t\tfor i := 0; i < 5; i++ {\n\t\t\t\tp, err := parent.Parent()\n\t\t\t\tif err != nil {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tparent = p\n","sourceCodeStart":1168,"sourceCodeEnd":1204,"githubUrl":"https://github.com/xpzouying/xiaohongshu-mcp/blob/332d196854a9eac0d2b8c2c0e3d0cc43139d724c/xiaohongshu/publish.go#L1168-L1204","documentation":"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.","triggerScenarios":"page.Elements(\"span.d-text\") fails because the tab was closed/navigated, the rod context expired, or the CDP session dropped during the query.","commonSituations":"Calling bindProducts after the page navigated or browser crashed; a canceled context (deadline) killing the evaluation; reconnect issues with a remote browser.","solutions":["Ensure the publish page is loaded and alive before binding products","Check the wrapped inner error for the underlying rod/CDP cause","Increase or fix context deadlines around the publish flow","Re-navigate and retry the publish step"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if page == nil { return errors.New(\"page is nil\") }\nif _, err := page.Info(); err != nil { return fmt.Errorf(\"page not alive: %w\", err) }","typeGuard":null,"tryCatchPattern":"if err := bindProducts(ctx, page, products); err != nil {\n    if strings.Contains(err.Error(), \"查找商品按钮文本失败\") {\n        // page context lost: re-navigate and retry once\n    }\n}","preventionTips":["Check page liveness before the products step","Avoid tab close/navigation during publish","Use adequate context timeouts so the query isn't canceled","Log the inner error to distinguish navigation from CDP failure"],"tags":["go-rod","selector","page-lifecycle"],"backgroundTag":"rod-page-context-canceled","analyzedSha":"332d196854a9eac0d2b8c2c0e3d0cc43139d724c","analyzedAt":"2026-09-05T22:22:55.988Z","contentChangedAt":"2026-09-05T22:22:55.988Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}