【发布时间】:2019-04-09 14:23:05
【问题描述】:
我有一个基于Selenium WebDriver 的测试,它填写表格并将其发送以进行处理。在处理期间打开一个窗口。有时处理失败,但是这个窗口没有关闭,所以我们不能得到结果。这个测试的目的是得到结果。我尝试为此窗口设置超时,因此它应该在WebDriver 预定义的时间(我现在将其设置为 10 秒)后关闭,并且应该重新发送表单。我使用以下代码。
WebElement webElement;
try {
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.findElement(sendButton).click();
webElement = wait.until(ExpectedConditions.presenceOfElementLocated(By.className("button-resultdown")));
} catch (TimeoutException ex) {
webElement = null;
} finally {
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
}
if (webElement == null) {
driver.findElement(popUpClose).click();
TimeUnit.SECONDS.sleep(4);
driver.findElement(sendButton).click();
}
弹窗不会在 10 秒后自动关闭。我检查了元素定位器,它们是有效的。
【问题讨论】:
标签: java selenium selenium-webdriver webdriver webdriverwait