How to get css class name using Selenium? How to get css class name using Selenium? selenium selenium

How to get css class name using Selenium?


From a WebElement you can use the getAttribute method like this:

element.getAttribute("class")


Yes, you can use getAttribute(attributeLocator) function for the your requirement.

 selenium.getAttribute(//xpath@class);

Specify the Xpath of the element for which you require to know the class of.

Thanks.


There is nothing depending on eclipse or java, in fact it is more about location strategy.If you want to access specific tr element with/without css class you can usecss locator:

css=tr:nth(indx_base_0)

nth row with class

css=tr.odd:nth(indx_base_0)

first row with class odd

css=tr.odd

Using xpath:

//tr[index_base_1]

first row with class odd

//tr[@class='odd']

nth row with class odd

//tr[@class='odd'][index_base_1]

Here are some useful examples