-
-
Notifications
You must be signed in to change notification settings - Fork 11
Attribute selectors
Greg Bowler edited this page Mar 4, 2026
·
2 revisions
Attribute selectors are fully supported, including quoted values and operator variants.
-
[required]checks attribute presence. -
[name=email]exact value match. -
[name='email']and[name="email"]are both supported.
-
[attr*=value]contains substring. -
[attr~=value]contains whole word in a space-separated list. -
[attr$=value]ends with. -
[attr|=value]exact value or value followed by hyphen. -
[attr^=value]starts with.
| CSS | XPath |
|---|---|
[data-categories*=test] |
.//*[contains(@data-categories,"test")] |
[data-categories~=example] |
.//*[contains(concat(" ",@data-categories," "),concat(" ","example"," "))] |
[data-test-thing$=test] |
.//*[substring(@data-test-thing,string-length(@data-test-thing) - string-length("test") + 1)="test"] |
| `[class | =en]` |
[class^=class1] |
.//*[starts-with(@class, "class1")] |
- Values containing commas are handled correctly, for example:
[data-ga-client='(Test) Message, this has a comma']. - Values containing square brackets are supported, such as:
[name='choice[]'].
Continue learning about pseudo selectors.
PHP.GT/CssXPath is a separately maintained component of PHP.Gt/WebEngine.