What's happening is that when the user tries to navigate away from this page via a link (or close the page/browser tab) he's prompted with browser's standard:
  • "Are you sure you want to leave this page?" dialog
  • with "Leave this page" and "Stay on this page" buttons
Every web browser has a slightly different message, (the message text here is from IE; other browsers will display different text, but the behavior is the same). For example, see the screenshot below:

 
They had tried the following code in Rapise:
  • DoSetExpectedConfirmResult() and DoSetExpectedPromptResult()
 
Both following pieces of code have no effect - the dialog displays anyway.
 
Navigator.DoSetExpectedConfirmResult(false);
SeS('Cancel').DoClick();    // click "Cancel" link
Navigator.DoCheckConfirmation("Are you sure you want to leave this page?");

 

 
Navigator.DoSetExpectedPromptResult(false);
SeS('Cancel').DoClick();    // click "Cancel" link
Navigator.DoCheckPrompt("Are you sure you want to leave this page?");

 

Now, some other testing tools (e.g. Selenium) that only can handle browser events by calling the browser event directly, require complex workarounds, e.g. suppressing the popup by providing empty callback function for window.onbeforeunload() as follows:
 
window.onunload = function() {};

 

However, because Rapise can also simulate mouse clicks using the DoLClick() function, there is an easier way.

When recording, simply learn the Cancel button using CTRL+2 during recording.

Now we cannot use the normal code:
SeS('Cancel').DoClick();

blocks because it sends event, and event calls onbeforeunload handler that is stuck. So we need to use the "real click" LClick method instead, like this:

SeS('Cancel').DoLClick();

// Now popup may show up, wait a bit
Global.DoSleep(500);

// Now press 'Leave'. Simplest way - just press Enter key, because leave is focused by default
Global.DoSendKeys("{ENTER}");
And voila, it will now handle the case correctly.