Selenium 2 WebDriver UnhandledAlertException Java

北城以北 提交于 2019-12-06 15:32:11
Michael Laffargue

Did you try using Robot? Something like :

     Alert alert = driver.switchTo().alert();
     Robot a = new Robot();
     a.keyPress(KeyEvent.VK_ENTER);

Why robot and not Actions

From this answer :

There is a huge difference in terms of how do these tools work. Selenium uses the WebDriver API and sends commands to a browser to perform actions (through the "JSON wire protocol").

Java AWT Robot uses native system events to control the mouse and keyboard.

If you are doing browser automation, ideally, you don't ever use things like Robot since usually the functionality provided by selenium is more than enough. Though, there are cases when there is a browser or native OS popup opened, for example, to upload/download a file - this is something that can be also solved with Robot -

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!