利用selenium webdriver点击alert提示框

在进行元素定位时常常遇到这样的alert框:

那么该如何定位并点击确定或取消按钮呢?stackoverflow上找到了这个问题的答案。

 

OK, Show you the code:

1 driver.findElement(By.id("updateButton")).click();
2 //pop up with id "updateButton" opens
3 Alert alert = driver.switchTo().alert();
4 //update is executed
5 alert.accept();

如果是点取消,则:

alert.dismiss();

 

附几个相关链接:

http://www.cnblogs.com/qiaoyeye/p/5593428.html

http://sanwen8.cn/p/w3dEEE.html

 

posted @ 2016-12-12 10:37  小淞鼠  阅读(6088)  评论(0编辑  收藏  举报