如何通过Java使用Selenium WebDriver等待所有加载程序消失 [英] How to wait until all loaders disappears using Selenium WebDriver through Java

查看:54
本文介绍了如何通过Java使用Selenium WebDriver等待所有加载程序消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Selenium Web驱动程序,我需要等待所有加载程序消失.我在仪表板页面上有12个小部件,我需要等到所有小部件都加载完毕.加载程序显示在每个小部件上.我已经使用了以下两种方法,但是没有任何效果,也没有错误,它只会传递到下一条语句.

I am using selenium web driver and I need to wait until all loaders disappear. I have 12 widgets on dashboard page and I need to wait until all widgets are loaded. Loader shows on each widget. I have used both following ways but nothing works and no errors, it just passes on to next statement.

new WebDriverWait(driver,60)
.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//div[contains(text(),'Loader')]"))); 

WebDriverWait wait2 = new WebDriverWait(driver,60);
wait2.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector("div.loader")));

推荐答案

由于您在仪表板页面上总共有12个小部件,并且需要等待所有小部件加载完毕,因此必须诱使 WebDriverWait 定位器策略:

As you are having total 12 widgets on dashboard page and you need to wait until all widgets are loaded you have to induce WebDriverWait for the invisibilityOfAllElements() and you can use either of the following Locator Strategies:

  • cssSelector :

new WebDriverWait(driver, 20).until(ExpectedConditions.invisibilityOfAllElements(driver.findElements(By.cssSelector("div.loader"))));

  • xpath :

    new WebDriverWait(driver, 20).until(ExpectedConditions.invisibilityOfAllElements(driver.findElements(By.xpath("//div[@class='loader']"))));
    

  • 这篇关于如何通过Java使用Selenium WebDriver等待所有加载程序消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆