How can I find an element by CSS class with XPath ?
To find element by CSS class with Xpath:
The selector must work and will be more efficient if it replace with correct markup.
div is a sought element,
This will match cases like class=”Testvalue” or class=”newTest”.
//div[contains(concat(' ', @class, ' '), ' Test ')]
Certainly it will match correctly and also use the normalize-space function to clean up stray whitespace characters around the class name.
//div[contains(concat(' ', normalize-space(@class), ' '), ' Test ')]
In all the versions, the * should be replaced by element name that actually match, or search each and every element in the document for the given condition.