[英]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).假设我有一个 web 页面,该页面有记录,显示在表格中(有几列)。 Now there is search-input-box and a search-button .现在有search-input-box和search-button 。 Using those I am searching for records with an id in the table .使用那些我在 table 中搜索具有 id 的记录。
I am using implicit wait which seems to be working fine in most of the cases and failing under this scenario:我正在使用隐式等待,这在大多数情况下似乎都可以正常工作,但在这种情况下会失败:
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):似乎它没有找到足够的时间来刷新表并仍然显示所有记录,即使我使用(对于表中的 id 列)进行搜索:
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.如果我在单击搜索按钮后使用Thread.sleep() ,那么一切都很好,因为我看到表格已经刷新了预期的结果。 However, I have to avoid using thread.sleep.但是,我必须避免使用 thread.sleep。
May I get any suggestion on how can I make it wait until the table has been refreshed with searched data?我可以就如何让它等到用搜索到的数据刷新表得到任何建议吗?
If you know that the id is unique which you are searching, in that case, you can do like this:如果您知道要搜索的 id 是唯一的,在这种情况下,您可以这样做:
After clicking the search
button wait for records size be 1单击search
按钮后,等待记录大小为 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:如果您搜索的id
不是唯一的并且搜索后您可以看到多个结果,您可以这样做:
Before clicking the search
button you can get the size of records在单击search
按钮之前,您可以获得记录的大小
int size = records.size();
After clicking the search
button you can wait for records size be increased:单击search
按钮后,您可以等待记录大小增加:
wait.until(driver -> records.size() < size);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.