当我 运行 使用 java 在 selenium 中进行测试时,警报关闭但在代码中显示失败
When I run test in selenium using java, the alert gets closed but in code it shows failure
添加详细信息
在我的测试中,我尝试单击我正在使用 .accept() 函数的警报弹出窗口上的 'ok' 按钮。在执行时,脚本能够成功单击确定按钮,正如我在应用程序功能中看到的那样,但在详细报告中,由 eclipse 生成的报告将特定测试步骤显示为失败。
我正在使用 Alert myAlert = driver.switchTo().alert();
myAlert.accept();
根据您的说法,您可以接受警报,但测试步骤在控制台中显示异常:
您可以捕获异常并继续执行后续步骤:
下面是代码:
try {
Alert myAlert = driver.switchTo().alert();
myAlert.accept();
} catch (Exception e) {
System.out.println("######### Successfully Accepted Alert ################");
}
// here proceed with your next steps.
希望对您有所帮助。
添加详细信息
在我的测试中,我尝试单击我正在使用 .accept() 函数的警报弹出窗口上的 'ok' 按钮。在执行时,脚本能够成功单击确定按钮,正如我在应用程序功能中看到的那样,但在详细报告中,由 eclipse 生成的报告将特定测试步骤显示为失败。 我正在使用 Alert myAlert = driver.switchTo().alert(); myAlert.accept();
根据您的说法,您可以接受警报,但测试步骤在控制台中显示异常: 您可以捕获异常并继续执行后续步骤: 下面是代码:
try {
Alert myAlert = driver.switchTo().alert();
myAlert.accept();
} catch (Exception e) {
System.out.println("######### Successfully Accepted Alert ################");
}
// here proceed with your next steps.
希望对您有所帮助。