Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
62
rated 0 times [  68] [ 6]  / answers: 1 / hits: 15613  / 10 Years ago, tue, december 16, 2014, 12:00:00

I am new to selenium web driver right now i am facing the issue while getting the class name of an element
the html of the element look like



<input id=filter-colour-0237739001><div class=detailbox detailbox-pattern unavailable-colour><span></span><img src=//lp2.hm.com/hmprod?set=source[/fabric/2014/9B57A69A-FD8D-4D79-9E92-8F5448566C51.jpg],type[FABRICSWATCH]&hmver=0&call=url[file:/product/main] alt= title=>




so i want to extract the class name which is class=detailbox detailbox-pattern unavailable-colour by using selenium web driver.
I got the element by the below code



WebElement ele=driver.findElement(By.id(filter-colour-0237739001));


now i want the class so can you please help me on this , i am okay with java script also


More From » java

 Answers
12

Simply use getAttribute()



WebElement ele=driver.findElement(By.xpath(//*[@id='filter-colour-0237739001']/../div));
ele.getAttribute(class)


EDIT I guess you wanted the class of div so you should be using a selector pointing to div such as //*[@id='filter-colour-0237739001']/../div as xpath


[#68473] Friday, December 12, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jarod

Total Points: 62
Total Questions: 111
Total Answers: 83

Location: Saint Vincent and the Grenadines
Member since Sat, Sep 11, 2021
3 Years ago
jarod questions
;