经常会碰到,页面操作后,出现一个alert窗口或者prompt确认窗口的情况,这时需要获得窗口的提示信息以及点击确定或取消的情况。
// Get a handle to the open alert, prompt or confirmation
Alert alert = driver.switchTo().alert();
// Get the text of the alert or prompt
alert.getText();
// And acknowledge the alert (equivalent to clicking "OK")
alert.accept();
这是通用的处理方法。但是如果弹出的窗口不是alert()
或者prompt()
弹出来的则不适用。请注意。