简体   繁体   中英

How to check whether the count is increased or not using selenium webdriver

WebElement element = driver.findElement(By.xpath("//*[@id='filter-row']/div[2]"));

String text = element.getText(); // 7 humans 

How can I read the number 7 only from that text

Code snippet for parsing number from a text:

String numberFromText = text.replaceAll("\\D+", ""); // removes all non-numerical characters from text

If you need the value as int/long then do one of the followings:

int totalHuman = Integer.valueOf(numberFromText);

or

long totalHuman = Long.valueOf(numberFromText);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM