Search code examples
c#watin

WatiN handling the IE 11 “Are you sure you want to leave this page?” popup


I have been trying using this code

WatiN.Core.DialogHandlers.ReturnDialogHandler myHandler = new WatiN.Core.DialogHandlers.ReturnDialogHandler();
browser.AddDialogHandler(myHandler);

myHandler.WaitUntilExists();

myHandler.OKButton.Click();
browser.RemoveDialogHandler(myHandler);

for handling a popup a website is causing when trying to leave the page in an onbeforeunload handler. Watin triggers this when trying to close the browser.

The above code does not seem to work on ie11. There is a special handler for ie9 but none for ie11.


Solution

  • I found a way of turning off the dialog. I already have a global variable that determines whether or not the dialog is displayed or not called link_was_clicked. By setting it to true in the watin code like this

    browser.RunScript(@"link_was_clicked = true;");
    

    it effectively turns it off.