How can I check if a selenium web element contains a specific css class.
I have this html li element
Improving on @uesports135 answer, "classess" should be a String array.
public boolean hasClass(WebElement element, String htmlClass) {
String[] classes = element.getAttribute("class").split("\\s+");
if (classes != null) {
for (String classAttr: classes) {
if (classAttr.equals(htmlClass)) {
return true;
}
}
}
return false;
}