What s the difference between functions getClass and getAttribute class in Selenium

0 votes

Kindly check this code

`<div class="datepicker dropdown-menu" style="display: block; top: 301px; left: 308px;">
<div class="datepicker-days" style="display: block;">
<div class="datepicker-months" style="display: none;">
<div class="datepicker-years" style="display: none;">

I'm trying get the classname of Divs present inside Div with classname(datepicker dropdown-menu") but it work with  wdriver.getAttribute("class").toString(); and not with wdriver.getclass().toString();. Can anybody tell me what is the difference?

Apr 7, 2018 in Selenium by Martin
• 4,320 points

1 answer to this question.

0 votes

The simple difference is that, getClass() returns the XPath of the webelement. Whereas, getAttribute("class") will return the value of the class attribute within the <div> tags. Look at the code below to understand this concept better.

    WebElement ele = driver.findElement(By.xpath(".//*[@id='next']"));
    String a = ele.getAttribute("class");
    string b = ele.getClass();

And if the html code was this:-

<input id="next" class="rc-button rc-button-submit" type="submit" value="Next" name="signIn"/>

Then, a will return: "rc-button rc-button-submit". Whereas, b will return: ".//*[@id='next']"

Hope the explanation was clear.

answered Apr 7, 2018 by nsv999
• 5,500 points

Related Questions In Selenium

0 votes
2 answers
+1 vote
2 answers

What is the difference between findElement and findElements in Selenium Webdriver?

FindElement Command -This method locates for the ...READ MORE

answered Feb 11, 2020 in Selenium by anonymous
0 votes
1 answer

What is the difference between WebDriver and RemoteWebdriver in Selenium?

Hey Ishan, the difference between Webdriver and ...READ MORE

answered May 10, 2019 in Selenium by Pratibha
• 3,690 points
0 votes
1 answer

What is the difference between getWindowHandle() and getWindowHandles() methods in Selenium WebDriver?

Hey Jennifer, difference between getWindowHandle() and getWindowHandles() ...READ MORE

answered Jun 4, 2019 in Selenium by Anvi
• 14,170 points
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...