簡體   English   中英

如何在Selenium Webdriver(Java)中從Web元素獲取數值

[英]How to get a numeric value from a webelement in Selenium Webdriver (Java)

 <div> id: 123456 has been successfully submitted. <br/> <br/> </div> 

在上面的代碼中,我能夠檢索整個文本。 但是我需要在這里檢索ID值123456並將其存儲在Excel工作表中。 幫助我檢索數值嗎?

提前致謝

要從字符串中提取數值:

int i = Integer.parseInt(html.replaceAll("\\D", ""));

正則表達式\\D表示“任何非數字”,而replaceAll()通過將所有非數字替換為空來刪除所有非數字。

暫無
暫無

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

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