How can I check the increment counter next to a field using webdriver / Java?

I have a field that displays a counter next to it, and whenever a new item is added to the field, the score is incremented by one. I want to get an incremented score every time to make sure a new item is added to the field. Below is the field that displays the counter

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

      

+3


source to share


1 answer


You can quickly calculate the counter and validate it with a known or previous invoice.



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

      

+3


source







All Articles