{"record":{"id":"1dbf8a704f5b351c","repo":"jackwener/OpenCLI","slug":"failed-to-set-fieldname-expected-text-go","errorCode":null,"errorMessage":"Failed to set ${fieldName}. Expected \"${text}\", got \"${actual}\". Debug screenshot: /tmp/xhs_publish_${fieldName}_debug.png","messagePattern":"Failed to set (.+?)\\. Expected \"(.+?)\", got \"(.+?)\"\\. Debug screenshot: /tmp/xhs_publish_(.+?)_debug\\.png","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"clis/xiaohongshu/publish.js","lineNumber":406,"sourceCode":"        fireInput(el, expectedText);\n        el.dispatchEvent(new Event('change', { bubbles: true }));\n        el.blur();\n        const actual = normalize(el.innerText || el.textContent || '');\n        return { ok: actual === normalize(expectedText), actual };\n      })(${JSON.stringify(located.sel)}, ${JSON.stringify(text)})\n    `);\n        }\n        catch {\n            result = await applyInPage();\n        }\n    }\n    else {\n        result = await applyInPage();\n    }\n    if (!result?.ok) {\n        await page.screenshot({ path: `/tmp/xhs_publish_${fieldName}_debug.png` });\n        const actual = typeof result?.actual === 'string' ? result.actual : '';\n        throw new Error(`Failed to set ${fieldName}. Expected \"${text}\", got \"${actual}\". Debug screenshot: /tmp/xhs_publish_${fieldName}_debug.png`);\n    }\n}\n/**\n * Add topic hashtags by driving the editor's native inline \"#\" flow.\n *\n * Modern XHS creator-center editors turn a \"#keyword\" typed into the note body\n * into a linked topic entity only after the author picks an item from the\n * suggestion dropdown that appears while typing. There is no standalone\n * \"添加话题\" search input anymore, so we type directly into the body editor.\n *\n * For each topic we:\n *   1. focus the body contenteditable and move the caret to the end,\n *   2. type \" #<topic>\" using native CDP insertion (falls back to execCommand)\n *      so XHS fires its inline suggestion dropdown,\n *   3. wait for the dropdown, then click the suggestion whose text best matches\n *      the topic (falling back to the first suggestion, then to Enter),\n *   4. confirm a topic chip/link was produced before moving on.\n *","sourceCodeStart":388,"sourceCodeEnd":424,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/publish.js#L388-L424","documentation":"Thrown by fillField during the verify phase: after inserting text, the field's normalized value did not equal the expected text. result.ok was false and result.actual holds whatever the field actually contained. A debug screenshot is saved before throwing.","triggerScenarios":"XHS editor truncated or reformatted the text (length limits, emoji/mention transformation); insertText went to the wrong element or was swallowed; asynchronous editor state lagged the immediate verification; IME/placeholder interference.","commonSituations":"Titles over XHS's character limit; content with special characters the editor rewrites; very slow pages where verification ran before the editor updated.","solutions":["Shorten the text to respect XHS title/body length limits and simplify special characters.","Look at /tmp/xhs_publish_<field>_debug.png to see what the field actually holds.","Retry with a longer wait before/after inserting text.","Update the CLI if XHS changed editor behavior; file an issue with the screenshot."],"exampleFix":"// before\nawait xhs.publish({ title: 'x'.repeat(100), ... }); // exceeds XHS title limit\n// after\nconst title = 'x'.repeat(100).slice(0, 20); // XHS title cap\nawait xhs.publish({ title, ... });","handlingStrategy":"try-catch","validationCode":"// respect XHS limits before calling\nif (opts.title && opts.title.length > 20) throw new Error('XHS title max ~20 chars');\nif (opts.content && opts.content.length > 1000) throw new Error('body too long');","typeGuard":null,"tryCatchPattern":"try {\n  await xhs.publish(opts);\n} catch (err) {\n  const m = err.message.match(/Failed to set (\\w+)\\. Expected \"([\\s\\S]*)\", got \"([\\s\\S]*)\"/);\n  if (m) console.error(`Field ${m[1]} mismatch: got \"${m[3]}\" — check limits/characters`);\n  else throw err;\n}","preventionTips":["Keep titles within XHS length limits","Avoid exotic characters/emoji that editors rewrite","Inspect the debug screenshot to see actual field content","Retry with longer waits on slow pages"],"tags":["automation","puppeteer","verification","xiaohongshu"],"backgroundTag":"text-input-verification-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}