我想实现自定义等待方法,应该等到加载弹出窗口可见。Customwait - 检查元素是可见/消失与硒webdriver(元素是在DOM中,但不可见)
此加载弹出框有它自己的id =“wait”。我用这个自定义expectedConditions(从#1),以检查它:就当装载仍清晰可见,我不知道为什么
public static ExpectedCondition<Boolean> absenceOfElementLocated(
final WebElement element) {
return new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
try {
element.isDisplayed();
return false;
} catch (NoSuchElementException e) {
return true;
} catch (StaleElementReferenceException e) {
return true;
}
}
@Override
public String toString() {
return "element to not being present: " + element.getText();
}
};
}
我的脚本通。
谢谢!
您可以使用WebDriverWait暂停执行,直到预期条件成立。 ex: WebDriverWait wait = new WebDriverWait(driver,30000); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(“yourPopUpId”))); –
谢谢,我试过了,但没有奏效。驱动程序无法识别弹出窗口的更改。 – brobee
尝试使用JavascriptExecutor并执行操作 – iamsankalp89