如何使用 WebDriver 检查警报是否存在? [英] How to check if an alert exists using WebDriver?
本文介绍了如何使用 WebDriver 检查警报是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要检查 WebDriver 中是否存在 Alert.
I need to check the existence of Alert in WebDriver.
有时会弹出警告,但有时不会弹出.我需要先检查警报是否存在,然后我可以接受或关闭它,否则它会说:未找到警报.
Sometimes it pops up an alert but sometimes it will not pop up. I need to check if the alert exists first, then I can accept or dismiss it or it will say: no alert found.
推荐答案
public boolean isAlertPresent()
{
try
{
driver.switchTo().alert();
return true;
} // try
catch (NoAlertPresentException Ex)
{
return false;
} // catch
} // isAlertPresent()
检查这里的链接 https://groups.google.com/论坛/?fromgroups#!topic/webdriver/1GaSXFK76zY
这篇关于如何使用 WebDriver 检查警报是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文