XPath for all elements with any attribute with specific value? XPath for all elements with any attribute with specific value? selenium selenium

XPath for all elements with any attribute with specific value?


First, you have to transform HTML into xhtml if you want to apply xpath selections on it.

The xpath for selecting an (x)html element having a specified value in one of its attributes is:

//*[@*="specified value"]


Here are XPath expressions for selecting...

  • All elements:

    //*
  • All elements with an attribute, a:

    //*[@a]
  • All elements with an attribute a equal to v:

    //*[@a='v']
  • All elements with any attribute:

    //*[@*]
  • All elements with any attribute equal to v:

    //*[@*='v']

Credit to Pierre for first posting //*[@*='v']. Please upvote his answer.


//*[@*[contains(.,'val')]]Will find any descendant node from the root with any attribute containing 'val' in its value.