簡體   English   中英

在Selenium Web驅動程序Java中獲取元素的類名稱

[英]Get class name of the element in selenium web driver java

我是硒網絡驅動程序的新手,現在我遇到了問題,同時獲取元素的類名以及該元素的html看起來像

<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="">

所以我想通過使用Selenium Web驅動程序提取類名稱,該類名稱為class =“ detailbox detailbox-pattern unavailable-colour”。 我通過以下代碼獲得了元素

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

現在我想要上課,所以您能在這方面幫我嗎,我也可以使用Java腳本

只需使用getAttribute()

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

編輯我想你想要div的類,所以你應該使用一個指向div的選擇器,例如//*[@id='filter-colour-0237739001']/../div作為xpath

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM