stagehand
stagehand copied to clipboard
Click misses a link that wraps onto two lines
What happens
When a link's text wraps onto two lines, clicking it with a locator (or through act()) reports success, but nothing happens. The click lands next to the link, not on it. Links that fit on one line work fine.
Why
click, hover and centroid aim at the centre of DOM.getBoxModel. For a link that wraps, that box covers both lines, so its centre can sit in the empty space beside the shorter line. The click then hits the parent element.
Steps to reproduce
- Open a page with a narrow paragraph and a link that wraps:
<p style="width:180px">Intro <a href="#" onclick="alert('hit')">a link whose text wraps</a> end.</p> - Click the link with a locator.
- The link's click handler never runs.
document.elementFromPointat the clicked point returns the<p>.
Expected
The click hits the link.
Suggested fix
Use DOM.getContentQuads, which returns one box per line, and click the centre of the first one, like Puppeteer and Playwright do. Fall back to the box model when there are none. I'm happy to open a PR.
Environment
- Stagehand: Go SDK v4.1.0 and v4.3.0 (bundled extension), also on
main - Found through dagu: dagucloud/dagu#3452