stagehand icon indicating copy to clipboard operation
stagehand copied to clipboard

fixed deepLocator() pathing bug

Open Mochael opened this issue 1 year ago • 2 comments

why

The logic in deepLocator was consolidating all the double // -> single /s, meaning that if I tried to do any sort of XPATH without specifying direct descendants, the query would break. So for example when I set my selector to `selector: xpath=//[@id='myID'] , it turns the locator into 'xpath=/[@id='myID']' removing the 2 slashes. This breaks my search because it's only looking for the ID in the root element, not across the descendants of the whole document (which is what I wanted)

what changed

I changed the logic so that it preserves the number of slashes in the xpath instead of splitting on "/", dropping all the slashes and then re-adding them

test plan

I tested locally but the stagehand team should verify that this works on whatever suite of tests they typically try. They should also probably add a test to catch this error like a search on non-direct descendants.

Mochael avatar Jul 14 '25 21:07 Mochael

⚠️ No Changeset found

Latest commit: db39fa02b92688d4ae54cec4f4003443932be4cb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Jul 14 '25 21:07 changeset-bot[bot]

Ran into this same bug, this is a big deal for repeatability. Have to use full xpath to items, can't reference by id. Came to see if someone else resolved. Please merge this in asap.

m3kessler1 avatar Jul 25 '25 18:07 m3kessler1