![](/img/trans.png)
[英]How to get value from “text” tag which is inside SVG tag in selenium java
[英]How to get the partial text of class value that is inside a tag
我想從下面的 html 元素中獲取文本“完成”
<div class="status">
<span class="statusText completed"></span>
</div>
xpath: //span[@class='statusText completed']
根據狀態——“已完成”、“進行中”或“錯誤”,我想進一步進行。 請幫我解決一下這個。
注意:沒有使用“getText()”方法檢索 span 元素的文本。
您需要使用getAttribute()
並獲取 class 屬性值,然后將其溢出以獲取最后一個字符串值。
WebElement element =driver.findElement(By.xpath("//span[contains(@class,'statusText')]"));
String[] strele = element.getAttribute("class").split(" ");
String status = strele[strele.length-1];
System.out.println(status);
String status = driver.findElement(By.xpath("//div[@class='status']")).getText();
status= status.split(" ")[1];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.