如何使用webdriver / Java检查字段旁边的增加计数?

时间:2015-05-23 14:12:53

标签: java selenium selenium-webdriver webdriver

我有一个字段显示旁边的计数,每当一个新项目添加到字段时,计数会增加一个。我希望每次都能获得增加的计数,以确保将新项目添加到该字段中。下面是显示计数

的字段
<span class="list-counting myone_qna_count">[2]</span>

1 个答案:

答案 0 :(得分:3)

您可以动态获取计数并根据已知或以前的计数进行验证。

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