stagehand icon indicating copy to clipboard operation
stagehand copied to clipboard

Click misses a link that wraps onto two lines

Open AniketR10 opened this issue 4 weeks ago • 0 comments

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

  1. 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>
    
  2. Click the link with a locator.
  3. The link's click handler never runs. document.elementFromPoint at 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

AniketR10 avatar Nov 04 '26 12:11 AniketR10