[fix]: extend support for xpaths containing predicates

Merged
SE
9mo ago
+1156-704

why

  • to make sure .count()/.nth() include shadow DOM matches
  • make sure common predicates work in shadow DOM selectors (beyond just attribute predicates)
  • also to unify xpath resolution into one shared resolver, building off of this PR

what changed

  • added shared resolver policy in packages/core/lib/v3/dom/locatorScripts/xpathResolver.ts
  • expanded composed predicate parsing/evaluation in packages/core/lib/v3/dom/locatorScripts/xpathParser.ts (attr existence, contains/starts-with, text(), normalize-space, and/or/not)
  • routed xpath entrypoints through the resolver:
    • packages/core/lib/v3/dom/locatorScripts/selectors.ts (resolveXPathMainWorld)
    • packages/core/lib/v3/dom/locatorScripts/counts.ts (countXPathMatchesMainWorld)
    • packages/core/lib/v3/dom/locatorScripts/waitForSelector.ts (xpath path now uses resolver)
  • also removed unused injected helper resolveSimpleXPath from packages/core/lib/v3/dom/piercer.runtime.ts & updated packages/core/lib/v3/dom/global.d.ts

test plan

  • packages/core/tests/xpath-parser.test.ts (expanded predicate parsing + evaluation coverage)
  • packages/core/tests/xpath-resolver.test.ts (shadow-inclusive count/nth ordering across composed tree)

Summary by cubic

Extended XPath support for predicates and shadow DOM, unified behind a shared resolver. Fixes .count() and .nth() with document-order DFS across light and shadow DOM, aligning with Linear STG-1373.

  • New Features

    • Predicate support: attr exists/equals/contains/starts-with; text()/normalize-space; and/or/not; positional [n].
    • Shadow-piercing resolution for selectors, count, and waitForSelector with native document.evaluate fallback and DFS indexing.
  • Refactors

    • Routed all XPath entry points to the shared resolver; removed legacy traversal and the piercer’s resolveSimpleXPath backdoor.
    • Expanded parser/resolver tests and added jsdom; cleaned dead code in selectors/counts/waitForSelector.