繁体   English   中英

如何在Selenium中等待警报框执行操作?

[英]How wait for alert box to perform the action in Selenium?

我按下取消按钮比根据我的代码检查一些文本。 在Chrome和Firefox中它工作正常但在IE中需要时间在警报框上执行操作,但代码移动到下一行。

所以我想要一些代码停止,直到操作在警告框中执行,然后进入下一步。 我正在使用硒进行自动化测试。

请找一段代码:

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());

您希望等到警报出现后再切换到它,类似于第3行。 参考。

编辑:尝试:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM