0

I'm looking to find all elements with a specific class, there can be multiple type of tags with that class name. Suppose I have div s, span s, p s, with same class and I need to find all of them based on class. How can i do it.

I tried:

//[contains(@class,'x')]

this doesn't work. Please suggest how I can achieve it.

Chakradar Raju
  • 2,691
  • 2
  • 26
  • 42

2 Answers2

2

You can try this

//*[@class="x"]
choroba
  • 231,213
  • 25
  • 204
  • 289
Mr. Alien
  • 153,751
  • 34
  • 298
  • 278
2

Try this:

//*[contains(concat(' ', normalize-space(@class), ' '), ' $classname ')]

You should use * to get all the elements.

Resource: XPath Select Element by Class

Mohammad Areeb Siddiqui
  • 9,795
  • 14
  • 71
  • 113
  • `' $classname '` is a literal string, not a concatenation of spaces with the value of the `$classname` variable. – LarsH Jul 29 '13 at 14:25