0
1.为什么不能关闭警报弹出窗口?为什么不能关闭警报弹出窗口?
- 我都试过警报等,它将关闭弹出,但然后我得到了奇怪的测试,其中弹出dosnt关闭/
上述代码的工作,但我得到其中惯于紧密而且会有测试失败奇数弹出。
使用以下所需的功能工作,但然后我在TestNG上得到一个错误,它说有一个'意外的弹出',但代码仍然是acepts并关闭弹出窗口。
我的代码:
System.setProperty("webdriver.chrome.driver", Constant.CHROME_DRIVER_DIRECTORY); DesiredCapabilities caps = DesiredCapabilities.chrome(); LoggingPreferences logPrefs = new LoggingPreferences(); logPrefs.enable(LogType.BROWSER, Level.ALL); UnexpectedAlertBehaviour.ACCEPT); caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs); webdriver = new ChromeDriver(caps);
3.我的代码:
public void closeAlertPopupBox() throws AWTException, InterruptedException {
try {
Alert alert = this.wait.until(ExpectedConditions.alertIsPresent());
alert.accept();
System.out.println("The popup has been successfully closed");
} catch (UnhandledAlertException f) {
Alert alert = this.driver.switchTo().alert();
alert.accept();
} catch (Exception e) {
System.out.println("Unable to close the popup");
Assert.assertFalse(true, "Unable to close the popup, Exception: " + e.getMessage());
}
}
为3号执行一些奇怪的原因会导致测试失败 – Gbru
警报警报= driver.switchTo()警报()。 alert.accept();或alert.dismiss(); –