Selenium WebDriver 如何关闭浏览器弹出窗口
问题描述:
我正在使用 selenium webDriver 为 Web 应用程序编写测试,并遇到一个场景,当我尝试关闭浏览器时,我收到一个弹出窗口,内容为您确定吗?该页面要求您确认是否要离开 -输入的数据将会丢失."带有 2 个按钮:离开页面和留在页面
I am writing tests for a web App using selenium webDriver and came across a scenario where when I try to close the browser I get a popup saying "Are you sure? The page is asking you to confirm that you want to leave - data entered will be lost." with 2 buttons: Leave Page and Stay on Page
如何点击这些按钮?
答
( ( JavascriptExecutor ) _driver )
.executeScript( "window.onbeforeunload = function(e){};" );
为我解决了这个问题