How to wait until all loaders disappears using Selenium WebDriver through Java

旧巷老猫 提交于 2021-02-04 08:18:22

问题


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")));


回答1:


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']"))));
    


来源:https://stackoverflow.com/questions/59574982/how-to-wait-until-all-loaders-disappears-using-selenium-webdriver-through-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!