Java 无法在selenium中使用显式(Fluent)等待找到动态加载的弹出窗口
我无法找到在我们的网站中动态显示的弹出窗口。元素最初处于以下html状态:Java 无法在selenium中使用显式(Fluent)等待找到动态加载的弹出窗口,java,selenium,Java,Selenium,我无法找到在我们的网站中动态显示的弹出窗口。元素最初处于以下html状态: <div class="notification_container" style = "display: none; overflow: hidden; float: none" </div> 以下是我的流畅等待声明: public void waitForElement(Wait<WebDriver> wait) { try { if (wait ==
<div class="notification_container" style = "display: none; overflow: hidden; float: none"
</div>
以下是我的流畅等待声明:
public void waitForElement(Wait<WebDriver> wait) {
try {
if (wait == null) {
this.wait = new FluentWait<WebDriver>(myBrowser)
// Timeout time is set to 60
.withTimeout(60, TimeUnit.SECONDS)
// polling interval
.pollingEvery(100, TimeUnit.MILLISECONDS)
// ignore the exception
.ignoring(NoSuchElementException.class, ElementNotVisibleException.class);
}
} catch (Exception e) {
System.out.println(+e.getMessage());
}
}
注意:此外,我尝试结合预期条件使用以下方法:
它们都失败,超时异常。如有任何帮助/指向正确方向,将不胜感激 与其等待特定属性,不如等待元素可见。。。这基本上就是你想做的。它已在
ExpectedConditions
中提供
wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("notification_container"));
为什么要
找到弹出窗口
?刚才我已经回顾了我之前的尝试,因为我已经在说明中提到了这一点。。即使对于我所传递的ElementLocated方法的可见性,className(“notification_container”)、“style”、“display:block”也将其更改为仅仅是定位器。。。工作出色!!有没有想过为什么attributesToBe和attributeContains方法会在这种特定情况下失败?我猜它是在寻找一个精确的字符串匹配,例如“display:block;overflow:hidden;float:none”,而不仅仅是一个子字符串,但我想我从来没有使用过attributesToBe
。你必须看一下文件才能看到。
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for value to contain "display: block;". Current value: "null" (tried for 60 second(s) with 100 MILLISECONDS interval)
wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("notification_container"));