如何在Internet Explorer弹出窗口下方处理“确定要离开此页面?"通过硒 [英] How to handle below Internet Explorer popup "Are you sure you want to leave this page?" through Selenium
问题描述
如何处理Selenium中的IE弹出窗口以下
How to Handle below IE Popup in Selenium
推荐答案
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() {};");
这篇关于如何在Internet Explorer弹出窗口下方处理“确定要离开此页面?"通过硒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!