0

How to handle "Are you sure you want to leave this page" popup using watin

I have open one link,after that when i open another link it gives a popup like

"Are you sure you want to leave this page"

how to handle this popup in watin.

  • Maybe you can disable it before with javascript (browser.Eval(...)) http://stackoverflow.com/questions/1119289/how-to-show-the-are-you-sure-you-want-to-navigate-away-from-this-page-when-ch – alonp Jul 04 '12 at 07:42

2 Answers2

2
WatiN.Core.DialogHandlers.ReturnDialogHandler.CreateInstance().OKButton.Click(); //IE8 or below

WatiN.Core.DialogHandlers.ReturnDialogHandlerIe9 ie9Handler = new WatiN.Core.DialogHandlers.ReturnDialogHandlerIe9(); //IE9
browser.AddDialogHandler(ie9Handler);
ie9Handler.CancelButton.Click();
browser.RemoveDialogHandler(ie9Handler);
0
browser.RunScript(@"
window.onbeforeunload = function ()
{
    event.returnValue = 'Are you sure you want to leave this page?';
}
");
yongfa365
  • 352
  • 3
  • 7