Aditya
Aditya

Reputation: 505

How to check the increase count beside a field using webdriver/Java?

I have a field which displays count beside it and whenever a new item is added to the field the count gets increase by one. I want to get the increased count every time to make sure that a new item is added to the field. Below is the field which displays the count

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

Upvotes: 3

Views: 1029

Answers (1)

Saifur
Saifur

Reputation: 16201

You can grab the count dynamically and validate that against a known or previous count.

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

Upvotes: 3

Related Questions