English 中文(简体)
How to avoid onbeforeunload preventing Watir test from exiting
原标题:

I have a webpage that uses onbeforeunload to prompt the user for confirmation whenever they try and navigate away from the page. This confirmation even fires when the browser window is closed.

My problem is that this prompt is preventing Watir from closing IE at the end of a test run, at least until I manually intervene and click "OK".

How can I write my tests such that Watir automatically dismisses this prompt, even if the test fails? I m thinking there might be some conditional logic in the test teardown method, but I need help interacting with the popup.

Note: I have a different question pertaining to interacting with the onbeforeunload prompt when it is created by a click event. This question is about handling that popup when it is created by a request to close the window.

问题回答

If you don t really need to test that dialog, you can overwrite onbeforeunload.

Not sure how it can be done in Watir, but in Watir-WebDriver it ll look like

browser.execute_script "window.onbeforeunload = null"




相关问题
页: 1

在用户离开网页时,我只想在网页上提交几种表格。 是否有这种“你拯救吗?”的问题,而我迄今为止的法典就是这样:

Javascript synchronous AJAX timeout

My Javascript needs to send some data to a server when the page closes, which I currently do with a synchronous AJAX (SJAX?) request in window.onbeforeunload. The problem with this, of course, is that ...

jQuery UI Dialog OnBeforeUnload

I have a small problem. I m attempting to catch the OnUnLoad Event of the Window and ask a confirmation question and if the user decides they want to stay then fine, and if they want to leave the ...

How to click on onbeforeunload prompt in Watir test?

I have a webpage that has an onbeforeunload script that prompts the user when they take an action that would navigate away from the current page. How do I interact with this popup using Watir? My ...

window.onbeforeunload not firing in child window

I want to bind a function to the beforeunload event of a child window in Javascript. I have the following code: newWind = window.open(settings.url, "Dialog", "width=" + settings.width + ",height=" + ...

热门标签