How to check if dom has a class using WebDriver (Selenium 2)? How to check if dom has a class using WebDriver (Selenium 2)? selenium selenium

How to check if dom has a class using WebDriver (Selenium 2)?


To expand on Sam Woods' answer, I use a simple extension method (this is for C#) to test whether or not an element has a specified class:

public static bool HasClass( this IWebElement el, string className ) {    return el.GetAttribute( "class" ).Split( ' ' ).Contains( className );}


Once you find the element, you can just call myElement.GetAttribute("class"). Then you can parse the string that is returned and see if it contains or does not contain the class name you care about.


You can use FindElement(By.ClassName(//name of your class)); I would recommend that you either loop through and search the DOM for a set period of time or set a Thread.sleep(xxxx) and then look for the appended class.