No Alert is present/No modal dialog found — WebDriver unable to catch JS error

I am automating an "Add Employee" form-based test for our production site. When an id is entered, or an email , or a name, that already exists, then, a service error is popped up that shows the employee cannot be registered. Even though this box comes up, the test passes :(. I tried using the driver.switchTo().alert() function in my code. This is what happened:


A lot of times what happens is the Selenium code executes before the browser renders the alert. What I tend to do is something like this:


Alert getAlert() {
    try {
        Alert alert = driver.switchTo().alert();
        return alert;
    } catch (NoAlertPresentException e) {
        // no alert to dismiss, so return null
        return null;
    }
}
I don't really think this is ideal, but I don't know of a better way in Selenium at the moment. I tend to just call this blindly from my tests at regular intervals, and if it returns an alert, I'll just dismiss it. If you are expecting an alert from your app and want to dismiss it before proceeding, wrap it in a while loop.


http://stackoverflow.com/questions/1176348/access-to-file-download-dialog-in-firefox
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值