且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Internet Explorer弹出窗口下方处理“确定要离开此页面?"通过硒

更新时间:2023-12-01 20:14:16

Internet Explorer 弹出窗口,其文本为确定要离开此页面吗? WindowEventHandlers.onbeforeunload

The Internet Explorer popup with text as Are you sure you want to leave this page? is the result of WindowEventHandlers.onbeforeunload

onbeforeunload 属性href ="https://developer.mozilla.org/zh-CN/docs/Web/API/WindowEventHandlers" rel ="nofollow noreferrer"> WindowEventHandlers mixin是 beforeunload 事件.当窗口即将卸载其资源时,会触发这些事件.此时,文档仍然可见,事件仍可取消.

The onbeforeunload property of the WindowEventHandlers mixin is the EventHandler for processing beforeunload events. These events fire when a window is about to unload its resources. At this point, the document is still visible and the event is still cancelable.

有多种策略可用于处理此弹出窗口.但是,作为跨浏览器解决方案,您可以禁用此对话框,调用executeScript()window.onbeforeunload设置为 function() {}; ,并且可以使用以下解决方案:

There are different strategies available to handle this popup. However, as a Cross Browser solution, you can disable this dialog invoking the executeScript() to set window.onbeforeunload as function() {}; and you can use the following solution:

((JavascriptExecutor)driver).executeScript("window.onbeforeunload = function() {};");

您可以在