所以我有一个自动化测试方法,VerifyAndDismissAlert()
try{
WebDriver WD = WebDriver();
Alert alert = WD.switchTo().alert();
alert.accept();
String alertText = alert.getText();
Pause(1);
SeleniumPlus.VerifyValues(AlertTextToVerify, alertText);
} catch (Exception e) {
e.printStackTrace();
}
当在 Chrome 中运行时,当尝试在输入框中输入内容时,警报会弹出并消失。
但是在 Internet Explorer 中,警报会弹出并且不会消失。似乎警报甚至没有被识别,因为当我被迫单击“确定”继续测试时,它会抛出
org.openqa.selenium.NoAlertPresentException: No alert is active
此测试与 Chrome 驱动程序完美配合,因此它必须与 IE 驱动程序一起执行某些操作。任何帮助将不胜感激!
最佳答案
使用ExpectedConditions等待警报出现,并且通过 alert.accept();
接受警报后您将收到 alert.getText()
,这肯定会抛出 NoAlertPresentException.Because 警报接受后就不会出现了。在接受或关闭警报之前,您必须对警报进行类似alert.getText() 的操作
WebDriverWait wait = new WebDriverWait(WD, 30);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = WD.switchTo().alert();
String alertText = alert.getText();
System.out.println(alertText);
alert.accept();
关于java - SeleniumPlus Internet Explorer 测试中输入区域文本警报不会消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31004490/