如何使用Selenium WebDriver通过Java等待所有加载程序消失

huangapple go评论76阅读模式
英文:

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

问题

我正在使用Selenium Web Driver,并且需要等待所有加载程序消失。我的仪表板页面上有12个小部件,我需要等待所有小部件都加载完毕。每个小部件上都显示加载程序。我已经尝试了以下两种方法,但都没有效果,也没有错误,它只是继续执行下一条语句。

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")));
英文:

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

如何使用Selenium WebDriver通过Java等待所有加载程序消失

答案1

得分: 1

您在仪表板页面上有共计12个小部件,需要等待所有小部件加载完毕,您可以使用_WebDriverWait_来等待invisibilityOfAllElements(),并且可以使用以下任一定位策略

  • css选择器
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']"))));
英文:

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

huangapple
  • 本文由 发表于 2020年1月3日 15:52:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/59574982.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定