如何使用webdriver / Java检查字段旁边的增加计数?
作者:互联网
我旁边有一个显示计数的字段,每当将新项目添加到该字段时,计数就会增加一.我想每次都增加计数,以确保将新项目添加到该字段中.以下是显示计数的字段
<span class="list-counting myone_qna_count">[2]</span>
解决方法:
您可以动态获取计数并针对已知计数或先前计数进行验证.
By css = By.cssSelector(".list-counting.myone_qna_count");
//This should replace all the [] and return the count in String format
java.lang.String stCount = driver.findElement(css).getText().replaceAll("\\[|\\]", "");
//Parse to int so that it can be used to do the comparison
int count = Integer.parseInt(stCount);
System.out.println(count); //should be 2 now
//Do a comparison with known value here
标签:selenium,selenium-webdriver,webdriver,java 来源: https://codeday.me/bug/20191120/2042709.html