Skip to content

Attribute selectors

Greg Bowler edited this page Mar 4, 2026 · 2 revisions

Attribute selectors

Attribute selectors are fully supported, including quoted values and operator variants.

Presence and exact match

  • [required] checks attribute presence.
  • [name=email] exact value match.
  • [name='email'] and [name="email"] are both supported.

Operator support

  • [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.

Examples

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")]

Special cases

  • 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.

Clone this wiki locally