Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.1k views
in Technique[技术] by (71.8m points)

Selenium [Java] : How can I make it wait until a table has been refreshed?

Assume that I have a web page that has records, displayed in a table ( that has several columns). Now there is search-input-box and a search-button. Using those I am searching for records with an id in the table.

I am using implicit wait which seems to be working fine in most of the cases and failing under this scenario :

  • I made the page to load all the data in the table after I logged in using implicit wait
  • Entered id in the search-input-box and clicked search-button
  • Now I am expecting only one record instead of all the records that were displayed in the table before the search happened

It seems that it did not find enough time to refresh the table and still showing all the records even though I do search with ( for the id columns in the table):

List<WebElement> idRows = driver.wait(<waittime>, <interval>).until(driver -> driver.findElement(By.id("column-id")));

If I use Thread.sleep() after clicking the search-button, everything is fine as I am seeing the table has been refreshed with the expected result. However, I have to avoid using thread.sleep.

May I get any suggestion on how can I make it wait until the table has been refreshed with searched data?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you know that the id is unique which you are searching, in that case, you can do like this:

After clicking the search button wait for records size be 1

wait.until(driver -> records.size() == 1);

In case when your searched id is not unique and after searching you can see multiple results, you can do it this way:

Before clicking the search button you can get the size of records

int size = records.size();

After clicking the search button you can wait for records size be increased:

wait.until(driver -> records.size() < size);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...