0
任何人可以把我扔我的查询的一些想法不以页面总是一个元素?如何等待使用webdriver的
查询: 在我的应用程序,有频繁自带的弹出,但有些时候它不来。 我必须检查弹出窗口是否存在,然后对其执行操作。这个弹出窗口还需要一些时间才能出现在页面中。
我的解决方案:首先 我等待弹出通过明确的等待状态。 然后通过if循环来检查弹出窗口是否显示在页面上。 如果显示则执行操作,否则执行其他操作。
现在,如果弹出不来,我m如果超时异常。
这里是我的代码:
FluentWait<WebDriver> wait_1 = new FluentWait<WebDriver>(driver)
.withTimeout(30, TimeUnit.SECONDS)
.pollingEvery(5, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class)
.ignoring(TimeoutException.class);
//getting time out exception if pop up does not exists
wait_1.until(ExpectedConditions.visibilityOfElementLocated(By.id("some id")));
if(driver.findElement(By.id("some id")).isDisplayed()) {
System.out.println(driver.findElement(By.id("some id")).getText());
//click some elements
}
else{
// `enter code here`
}
谢谢!我认为这会有所帮助。 – user3512254
@ user3512254这是否适合您? – xyz