如何等待警报框在Selenium中执行操作? [英] How wait for alert box to perform the action in Selenium?

查看:121
本文介绍了如何等待警报框在Selenium中执行操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按的是取消按钮,而不是根据我的代码,它正在检查某些文本.在Chrome和Firefox中,它工作正常,但在IE中,需要花一些时间对警报框执行操作,但是代码移至下一行.

I am pressing a cancel button than according to my code it is checking some text. In Chrome and Firefox it is working fine but in IE it is taking time to perform operation on alert box but code moves to next line.

所以我想要一些代码停止,直到在警报框上执行该操作,然后再执行下一步.我正在使用硒进行自动化测试.

So i want some code that stop till the operation is preformed on alert box and than it goes to next Step. I am doing automation testing using selenium.

请找到一段代码:

Alert al = driver.switchTo().alert();
al.accept();

wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//*[@id='content-body-full']/p[1]")));
assertEquals("Your cancellation request has been successfully executed.",driver.findElement(By.xpath(".//*[@id='content-body-full']/p[1]")).getText().toString());

推荐答案

您要等到警报出现后再切换到警报,类似于第三行. 参考.

You want to wait until the alert is present before switching to it, similar to your 3rd row. Reference.

尝试:

new WebDriverWait(driver, 60)
        .ignoring(NoAlertPresentException.class)
        .until(ExpectedConditions.alertIsPresent());

Alert al = driver.switchTo().alert();
al.accept();

这篇关于如何等待警报框在Selenium中执行操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆