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> </table>
Is there any way to get the class name 'odd' or 'even' using selenium? I
We can find an element using the attribute class name with Selenium webdriver using the locators - class name, css, or xpath. To identify the element with css, the expression should be tagname[class='value'] and the method to be used is By. cssSelector.
Type “css=input[type='submit']” (locator value) in Selenium IDE. Click on the Find Button. The “Sign in” button will be highlighted, verifying the locator value.
What are CSS Selectors in Selenium? CSS Selectors are one of the locator strategies offered by Selenium to identify the web elements. The CSS Selectors mainly use the character sequence pattern, which identifies the web elements based on their HTML structure.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With