This repository reproduces an issue with erroneous text node selection in Stagehand.
This is a minimal reproduction case that demonstrates text node selection behavior when Stagehand interacts with a simple HTML page containing clickable elements.
-
Start the server serving the test case HTML file in one terminal:
npm run serve
-
Run the Stagehand script in a second terminal:
npm start
Expected: Stagehand should successfully identify and click the "Card" element, triggering the JavaScript alert.
Actual: Stagehand fails to click on the "Card" element, eventually timing out.
The logged output (stored in stagehand.log for convenience) shows that the LLM is shown an accessibility tree with the text shown at the StaticText level, which causes the following action to be attempted:
{
category: 'action',
message: 'performing playwright method',
level: 2,
auxiliary: {
xpath: {
value: '/html[1]/body[1]/div[1]/div[1]/text()[1]',
type: 'string'
},
method: { value: 'click', type: 'string' }
}
}
This doesn't work because the XPath ends in /text()[1], but it would work if the XPath targeted the div instead.