stagehand-python@4.2.0a0.dev1541: fix(extension): read text() from direct child text nodes ( 2728) ( 3052)
Fixed an XPath parsing bug in Stagehand where text() was incorrectly treated as . (reading full element.textContent ), causing silent locator mismatches and incorrect element clicks on pages containing shadow roots.
原始内容为英文;当前页面提供中文导航与来源说明,具体事实请以原文为准。
为什么值得关注
In Stagehand's composed-tree XPath parser, which activates whenever a page contains a shadow root, text() was previously evaluated using element.textContent , identical to . . This caused locator evaluations to diverge from native document.evaluate() when handling nested markup, leading to incorrect matches or silent zero-result queries (such as selecting the wrong element on .first().click() ). The fix updates packages/extension/dom/locatorScripts/xpathParser.ts to distinguish between direct child text nodes ( text() ) and the element's string-value ( . ). Specifically: - text() = 'v' is now evaluated existentially across direct child text nodes. - contains(text(), 'v') and normalize-space(text()) = 'v' collapse the node-set to the string-value of the first text node, consistent with XPath specifications. - . retains its previous behavior reading the element's full subtree string-value. - If existing locators relied on text() matching nested child text, they must be updated to use . instead.
可执行摘要
Stagehand's composed-tree XPath parser ( xpathParser.ts ) now correctly evaluates text() against direct child text nodes instead of the entire subtree's element.textContent . This resolves behavioral divergence from native document.evaluate() on pages with shadow roots.
- Agent 实用度
- 72/100
- 可信度
- 96%
- 机器格式
- JSON + Markdown
开发者应核对什么
- Review existing XPath locators in automated tests or agent workflows: if any locator relied on text() matching deeply nested subtree text, update it to use . instead.