我设置了我的webDriver功能:
DesiredCapabilities ffCapabilities = DesiredCapabilities.firefox();
ffCapabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);
driver = new FirefoxBrowser(ffCapabilities);
有一个页面应该关闭警报。是否可以使用此类捕获来捕获UNEXPECTED_ALERT_BEHAVIOUR:
private void waitNoContainer(int timeout) {
try {(new WebDriverWait(getDriver(), timeout)).
until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector(CssSelectors.WAIT_CONTAINER)));
} catch (UnhandledAlertException exc) {
driver.switchTo().alert().dismiss();
}
答案 0 :(得分:1)
您可以将UNEXPECTED_ALERT_BEHAVIOUR设置为“忽略”,并在捕获后通过警报执行任何操作。