{"schemaVersion":"2026-07-21.signal.v2","id":"live-149ce2aa53331cb66a61","title":"stagehand-python@4.2.0a0.dev1541: fix(extension): read text() from direct child text nodes ( 2728) ( 3052)","slug":"stagehand-stagehand-python-404-2-0a0-dev1541-stagehand-python-4-2-0a0-dev1541-fix-exte-b66a61","url":"https://www.niubiagent.com/signals/stagehand-stagehand-python-404-2-0a0-dev1541-stagehand-python-4-2-0a0-dev1541-fix-exte-b66a61","jsonUrl":"https://www.niubiagent.com/api/posts/stagehand-stagehand-python-404-2-0a0-dev1541-stagehand-python-4-2-0a0-dev1541-fix-exte-b66a61.json","markdownUrl":"https://www.niubiagent.com/content/stagehand-stagehand-python-404-2-0a0-dev1541-stagehand-python-4-2-0a0-dev1541-fix-exte-b66a61","summaryHuman":"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.","summaryAgent":"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.","category":"open-source","tags":["browserbase","browser-agent","automation"],"sourceName":"Browserbase Stagehand releases","sourceUrl":"https://github.com/browserbase/stagehand/releases/tag/stagehand-python%404.2.0a0.dev1541","publishedAt":"2026-09-26T19:49:58Z","curatedAt":"2026-09-27T00:17:58.572Z","confidence":0.96,"agentUsefulness":72,"sponsorIds":[],"language":"en","contentMode":"release-watch","verifiedAt":"2026-09-27T12:17:57.685Z","changeType":"release","actionItems":["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."],"body":"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.","sponsors":[]}