feat(locator): add withClass, negation, and raw-predicate helpers#5524
Open
feat(locator): add withClass, negation, and raw-predicate helpers#5524
Conversation
…builder DSL Adds withClass (variadic, word-exact), withoutClass, withoutText, withoutAttr, withoutChild, withoutDescendant, and raw and()/andNot() escape hatches. Lets users express complex XPath like `not(.//svg)` and multi-class matches through the fluent builder instead of writing raw XPath. Also documents previously undocumented methods (or, withAttrStartsWith/EndsWith/Contains, as). withClassAttr is kept for backward compatibility and marked @deprecated in favor of withClass (word-exact) or withAttrContains('class', …) for substring matching. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…lass-negation # Conflicts: # docs/locators.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
locate()so complex XPath can be written as readable JavaScriptwithClass(...classes)(variadic, word-exact),withoutClass,withoutText,withoutAttr,withoutChild,withoutDescendantand(expr)/andNot(expr)for cases the DSL doesn't coveror,withAttrStartsWith,withAttrEndsWith,withAttrContains,aswithClassAttris kept for backward compatibility and marked@deprecated— preferwithClass(word-exact, matches CSS.foosemantics) orwithAttrContains('class', …)for substring matchingMotivation
Verbose XPath like
now becomes:
Naming note — why
withClassoverwithClassAttrwithClassAttremitscontains(@class, 'foo'), i.e. substring match, sowithClassAttr('btn')unintentionally matches elements withclass="btn-lg".withClassuses word-exact matching (same semantics as CSS.foo) and is variadic.Test plan
npx mocha test/unit/locator_test.js— 59 passing, including 10 new tests covering each new method🤖 Generated with Claude Code