user2335580
user2335580

Reputation: 408

Selenium: Wait for previous action to complete in java

I am new to Selenium. I am trying to automate the steps of filtering (by type = New)and sorting (by date descending) a table within a webpage using Selenium. I am using functions sendKeys() and click() for these operations.

I am using Thread.sleep(1000) between the sendKeys and click functions, so that the list is filtered by a category before it is sorted.

Is there a way to have the code wait till the page is filtered after the sendKeys() and then proceed with the click operation

Upvotes: 1

Views: 3004

Answers (1)

Auro Sarma
Auro Sarma

Reputation: 441

you can use WebDriverWait class to wait for some condition to be true. In your case you are sorting a table so, use the wait object to check the presence of any element's location after sorting. Here is the example code

WebDriverWait wait= new WebDriverWait(driver,30); //30 represents 30 secs
wait.until(ExpectedConditions.visibilityOfElementLocated(<Element locating stratergy>));

Make sure that, the element location which you are going to mention should be location of the element after sorting of your table.

Upvotes: 2

Related Questions