Selenium 等待元素出现和消失
Selenium wait for element to appear and dissapear
我有以下元素:
<div class="ui-helper-hidden" id="shell.indicator.busy">
<label>Processing...</label>
<br />
<img src="/RightCrowd/Images/loading.gif" alt="" />
</div>
它看起来像这样:
我想等待它出现然后消失并继续访问元素。这出现在 Web 应用程序的大多数页面上。我们已经尝试了一些东西,但有时它可以被 Selenium 看到,有时则不能,尽管我可以用眼睛看到它。
我认为此处理图像出现在当前页面的顶部,使用当前处理程序可能没有用。不确定。
我们试过这样的方法:
WebElement element = (new WebDriverWait(webDriver, 10))
.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//img[contains(@src,'/Images/loading.gif')]")));
boolean processingEnd = (new WebDriverWait(webDriver, timeoutWaitForProgressbar))
.until(ExpectedConditions.invisibilityOfElementLocated(By.id("shell.indicator.busy")));
所以我们已经尝试了 xpath 和 id...请告诉我处理这种情况的最佳方法是什么。
默认情况下,WebDriverWait
每半秒检查一次预期条件状态。我会尝试使用 FluentWait
class:
更频繁地发出预期的条件检查请求
Wait wait = new FluentWait(driver)
.withTimeout(timeoutWaitForProgressbar, SECONDS)
.pollingEvery(100, MILLISECONDS);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("shell.indicator.busy")));
我有以下元素:
<div class="ui-helper-hidden" id="shell.indicator.busy">
<label>Processing...</label>
<br />
<img src="/RightCrowd/Images/loading.gif" alt="" />
</div>
它看起来像这样:
我想等待它出现然后消失并继续访问元素。这出现在 Web 应用程序的大多数页面上。我们已经尝试了一些东西,但有时它可以被 Selenium 看到,有时则不能,尽管我可以用眼睛看到它。
我认为此处理图像出现在当前页面的顶部,使用当前处理程序可能没有用。不确定。
我们试过这样的方法:
WebElement element = (new WebDriverWait(webDriver, 10))
.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//img[contains(@src,'/Images/loading.gif')]")));
boolean processingEnd = (new WebDriverWait(webDriver, timeoutWaitForProgressbar))
.until(ExpectedConditions.invisibilityOfElementLocated(By.id("shell.indicator.busy")));
所以我们已经尝试了 xpath 和 id...请告诉我处理这种情况的最佳方法是什么。
默认情况下,WebDriverWait
每半秒检查一次预期条件状态。我会尝试使用 FluentWait
class:
Wait wait = new FluentWait(driver)
.withTimeout(timeoutWaitForProgressbar, SECONDS)
.pollingEvery(100, MILLISECONDS);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("shell.indicator.busy")));