XPath for all elements with any attribute with specific 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'].


//*[@*[contains(.,'val')]] Will find any descendant node from the root with any attribute containing 'val' in its 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"]