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

如何使用webdriver/Java检查字段旁边的增加计数?,java,selenium,selenium-webdriver,webdriver,Java,Selenium,Selenium Webdriver,Webdriver,我有一个字段,旁边显示count,每当一个新项目添加到该字段时,计数就会增加一。我希望每次都增加计数,以确保向字段中添加新项目。下面是显示计数的字段 <span class="list-counting myone_qna_count">[2]</span> [2] 您可以动态获取计数,并根据已知或以前的计数进行验证 By css = By.cssSelector(".list-counting.myone_qna_count"); //This should rep

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

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

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

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

我的情况是,我可能不知道以前的计数每次。因此,这种情况可能不会每次都适用于我。然后,首先获取计数并保存到变量>执行任何添加/增加计数的操作>再次获取计数并进行比较。我试试看。