如何处理“意外警报打开”? [英] How to handle the "unexpected alert open"?
本文介绍了如何处理“意外警报打开”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
由于弹出窗口,我遇到了Selenium抛出超时异常
的问题
I got an issue with Selenium throwing timeout exception
because of a pop up window
unexpected alert open
not provide any stacktrace information)
Command duration or timeout: 5 milliseconds
警报有确定
和取消
按钮。我知道有两种方法可以处理这个问题
The alert has OK
and CANCEL
buttons. I know two ways to handle this
第一种方式是重新开启新会话
The first way is reopen a new session
driver.quit();
driver = new ChromeDriver();
第二种方式是使用机器人类
Second way is using Robot class
Robot r = new Robot();
r.keyPress(KeyEvent.VK_ENTER);
r.keyRelease(KeyEvent.VK_ENTER);
但是,这种方法不具备时间效率。有没有更好的方法?
However, this methods are not time efficient. Is there any better way?
推荐答案
这应该可以解决问题:
driver.switchTo().alert().accept();
这篇关于如何处理“意外警报打开”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文