如何通过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']"))));