Skip to content

trim /text()[1] from xpaths #826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2025

Conversation

seanmcguire12
Copy link
Member

why

what changed

  • added a function trimTrailingTextNode which trims the text node from the xpath

test plan

  • run the following eval sets: act, observe, targeted_extract, combination, regression

Copy link

changeset-bot bot commented Jun 23, 2025

🦋 Changeset detected

Latest commit: c2800ba

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

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

@seanmcguire12 seanmcguire12 added act These changes pertain to the act function observe These changes pertain to the observe function combination These changes affect multiple Stagehand functions targeted-extract These changes pertain to targeted extract labels Jun 23, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

Added new trimTrailingTextNode utility function to fix text node interaction issues in XPath selectors, improving element targeting reliability.

  • Added new function in lib/utils.ts to remove /text()[1] from XPath selectors, preventing invalid Playwright operations
  • Modified lib/handlers/observeHandler.ts to use the new function when processing accessibility tree StaticText nodes
  • Fix ensures Playwright targets parent elements instead of text nodes for interactions
  • Solution specifically addresses issue #824 where LLM was selecting StaticText nodes incorrectly

2 files reviewed, no comments
Edit PR Review Bot Settings | Greptile

@seanmcguire12 seanmcguire12 merged commit 124e0d3 into main Jun 24, 2025
14 of 25 checks passed
@github-actions github-actions bot mentioned this pull request Jun 24, 2025
seanmcguire12 pushed a commit that referenced this pull request Jun 25, 2025
# Releases
## @browserbasehq/[email protected]

### Minor Changes

- [#819](#819)
[`6a18c1e`](6a18c1e)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - try
playwright click and fall back to JS click event

### Patch Changes

- [#826](#826)
[`124e0d3`](124e0d3)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix issue
where we are unable to take actions on text nodes

- [#818](#818)
[`1660751`](1660751)
Thanks [@miguelg719](https://github.com/miguelg719)! - Added CUA support
for Claude 4 models

- [#821](#821)
[`cadac9d`](cadac9d)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - use
playwright instead of playwright test

- [#832](#832)
[`759da55`](759da55)
Thanks [@miguelg719](https://github.com/miguelg719)! - Fix
\_refreshPageFromAPI to use parametrized apiKey

- [#810](#810)
[`a175a51`](a175a51)
Thanks [@miguelg719](https://github.com/miguelg719)! - Update logos

- [#822](#822)
[`8527a80`](8527a80)
Thanks [@miguelg719](https://github.com/miguelg719)! - Add model with
date tag for OpenAI CUA

- [#833](#833)
[`55fca2f`](55fca2f)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - adjust
stagehandLogger.warn() level to be 1 instead of 0

## @browserbasehq/[email protected]

### Patch Changes

- [#831](#831)
[`5812b02`](5812b02)
Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - added -man
& -h commands for explaining how to run evals

- Updated dependencies
\[[`124e0d3`](124e0d3),
[`6a18c1e`](6a18c1e),
[`1660751`](1660751),
[`cadac9d`](cadac9d),
[`759da55`](759da55),
[`a175a51`](a175a51),
[`8527a80`](8527a80),
[`55fca2f`](55fca2f)]:
    -   @browserbasehq/[email protected]

## @browserbasehq/[email protected]

### Patch Changes

- Updated dependencies
\[[`124e0d3`](124e0d3),
[`6a18c1e`](6a18c1e),
[`1660751`](1660751),
[`cadac9d`](cadac9d),
[`759da55`](759da55),
[`a175a51`](a175a51),
[`8527a80`](8527a80),
[`55fca2f`](55fca2f)]:
    -   @browserbasehq/[email protected]

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
act These changes pertain to the act function combination These changes affect multiple Stagehand functions observe These changes pertain to the observe function targeted-extract These changes pertain to targeted extract
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants