我正在使用ExpectedCondition
方法以确保元素消失,然后我的测试继续进行
wait.until(EC.invisibility_of_element_located((By.XPATH,busyIndicator)))
我正在做的是点击保存按钮。它将显示busyindicator对象。保存操作完成后,忙指示消失,表示保存操作已完成。
虽然busyindicator对象从UI中快速消失,但仍然我上面的webdriver命令需要将近30-40秒才能确保删除此元素。
需要帮助 1)如何优化上面的代码,以便快速执行 2)确保元素消失的其他更好的方法。
答案 0 :(得分:2)
确保您没有设置隐式超时或在等待之前将其设置为0:
driver.implicitly_wait(0)
WebDriverWait(driver, 30).until(EC.invisibility_of_element_located((By.XPATH,busyIndicator)))
隐式超时适用于任何命令,也适用于_find_element
使用的WebDriverWait
。
在您的情况下,可能会从DOM中删除忙碌指示符。显式等待不可见性调用find_element。由于元素不在DOM中,因此需要完成隐式超时。如果您有隐含的等待30秒,则需要30秒。然后只有显式等待才能成功完成。添加忙碌指示器可见的时间,您的时间为30-40秒。
答案 1 :(得分:0)
指定webDriver检查可见性的正常等待时间可以是FluentWait
或低ExplicityWait
。下面是Java Snippet我认为它会让你知道如何在其他绑定上实现。希望这有帮助
//Specify any less time
WebDriverWait wait = new WebDriverWait(driver, 5);
WebElement element = wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id('id')));
//FluentWait
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
.withTimeout(10, SECONDS)
.pollingEvery(5, SECONDS)
.ignoring(NoSuchElementException.class);
WebElement element = wait.until(new Function<WebDriver, WebElement>() {
public WebElement apply(WebDriver driver) {
return driver.findElement(By.id("someid"));
}
});