Maruf Hassan Maruf Hassan -5 years ago 169
Java Question

How to get css class name using Selenium?

I am new in selenium testing. I want to get the css class name using selenium. I am using eclipse and Java for development.

<table >
<tr class="odd"><td>Odd row</td></tr>
<tr class="even"><td>Even row</td></tr>
<tr class="odd"><td>Odd row2</td></tr>
<tr class="even"><td>Even row2</td></tr>

Is there any way to get the class name 'odd' or 'even' using selenium? I

Answer Source

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


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


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download