[英]No Alert is present/No modal dialog found — WebDriver unable to catch JS error
我正在为我们的生产站点自动化“添加员工”基于表单的测试。 当输入id,或已存在的电子邮件或名称时,会弹出一个服务错误,表明该员工无法注册。 即使这个框出现了,测试通过:(。我尝试在我的代码中使用driver.switchTo()。alert()函数。这就是发生的事情:
Alert alert=driver.switchTo().alert();
String text=alert.getText();
System.out.println(text);
使用Firefox 7 + Selenium WebDriver 2.8.0:
org.openqa.selenium.NoAlertPresentException: No alert is present (WARNING: The server did not provide any stacktrace information); duration or timeout: 2.11 seconds
Build info: version: '2.8.0', revision: '14056', time: '2011-10-06 12:41:48'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.37.6-0.7-desktop', java.version: '1.6.0_26'
Driver info: driver.version: RemoteWebDriver
使用Chrome +网络驱动程序:
[1011/131949:ERROR:automation_json_requests.cc(59)] JSON request failed: GetAppModalDialogMessage
with error: No modal dialog is showing
错误快照:
题:
如果我没有得到对话框的文本,那很好。 这是唯一会出现的警报。 所以,只要知道警报已经出现就可以解决我的问题。 但是,这两件事都说不存在警报/模态对话:(
谢谢。
编辑:我也试过这个:
Selenium selenium=new WebDriverBackedSelenium(driver,baseUrl);
System.out.println(selenium.isAlertPresent());
这给出了错误。 这不是警报箱吗? 它不是模态对话吗? 如果它不是那些东西,我怎么在页面上找到它的存在?
很多时候发生的事情是Selenium代码在浏览器呈现警报之前执行。 我倾向于做的是这样的事情:
Alert getAlert() {
try {
Alert alert = driver.switchTo().alert();
return alert;
} catch (NoAlertPresentException e) {
// no alert to dismiss, so return null
return null;
}
}
我真的不认为这是理想的,但我现在还不知道Selenium有更好的方法。 我倾向于定期从我的测试中盲目地调用它,如果它返回警报,我会解雇它。 如果您希望来自应用程序的警报并希望在继续之前将其解除,请将其包装在while循环中。
我也遇到了与模型对话框相同的问题。
你要做的是找到ok buttion的xpath并继续。
我也做了同样的事并成功完成了它。
找到webelement并在webelement和点击'ok'按钮之间等待。
不要使用像driver.switchto.alert.accept();
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.