DEV Community

Phạm Đức Huy
Phạm Đức Huy

Posted on

Answer: What is the correct XPath for choosing attributes that contain "foo"?

This XPath will give you all nodes that have attributes containing 'Foo' regardless of node name or attribute name:

//attribute::*[contains(., 'Foo')]/..

Of course, if you're more interested in the contents of the attribute themselves, and not necessarily their parent node, just drop the /..

//attribute::*[contains(., 'Foo')]

Top comments (0)