How to use Selenium using Xpath to determine the classes of an element? How to use Selenium using Xpath to determine the classes of an element? selenium selenium

How to use Selenium using Xpath to determine the classes of an element?


This <div/> element has one class attribute with one value, but this one is tokenized when parsed as HTML.

As selenium only supports XPath 1.0, you will need to check for classes like this:

//div[contains(@class, "LOGO1") or contains(@class, "LOGO2")]

Extend that pattern as needed and embed it in your expression.

With XPath 2.0 and better, you could tokenize and use the = operator which works on a set-based semantics:

//div[tokenize(@class, ' ') = ("LOGO1", "LOGO2")]


Old post but I'll put the solution I used up just in case it can help anyone.

xpath=//div[contains(@class,'carouselNavNext ')]/.[contains(@class, 'disabled')]

Fire of your contains, and then follow with /. to check children AND the current element.