admin管理员组

文章数量:1312998

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/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

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./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

Share Improve this question asked Dec 16, 2014 at 14:26 Prasad MagrePrasad Magre 411 gold badge1 silver badge5 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

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

本文标签: javascriptGet class name of the element in selenium web driver javaStack Overflow