Java 模态对话框存在异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18336483/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Modal dialog present Exception
提问by user2490373
I try to click on a
element, by this way:
我尝试a
通过这种方式点击元素:
WebElement title = driver.findElement(By.xpath("//a[text()=\"Delete this document library\"]"));
title.click();
When I click on it manually, its opens a window:
当我手动单击它时,它会打开一个窗口:
The page at http://.. says Are you sure you want to delete the selected items?
with OK
and Cancel
buttons
用OK
和Cancel
按钮
But when I run it with WebDriver (in Firefox 20.0
), I get the next error:
但是当我使用 WebDriver (in Firefox 20.0
)运行它时,出现下一个错误:
[Exception]: Modal dialog present
and I don't see even the window.
我什至看不到窗户。
What can be the reason?
原因是什么?
回答by Mark Rowlands
Sounds like you're encountering an Alert
.
听起来您遇到了Alert
.
Do this help?
这有帮助吗?
回答by Code Enthusiastic
You don't see the Alert when you run the test is because the default behavior of the WebDriver
is that it accepts alertwhen the Modal dialog present exception is thrown. It happens so fast that you can't see the alert.
您在运行测试时看不到警报是因为它的默认行为WebDriver
是它在引发模态对话框存在异常时接受警报。它发生得如此之快,以至于您看不到警报。
WebElement title = driver.findElement(By.xpath("//a[text()=\"Delete this document library\"]"));
title.click();
//Now the alert appears.
Alert alert = driver.switchTo().alert();
alert.accept();
回答by mihai_f87
If an alert window doesn't appear every time, you could do this:
如果不是每次都出现警报窗口,您可以这样做:
try {
Alert alert = driver.switchTo().alert();
alert.accept();
//if alert present, accept and move on.
}
catch (NoAlertPresentException e) {
//do what you normally would if you didn't have the alert.
}
回答by Kuladip
alert.dismiss() or or Press Esc button you can dismiss the alert. For my case for this is solved this issue.
alert.dismiss() 或 或 按 Esc 按钮您可以关闭警报。对于我的情况,解决了这个问题。