This is a migrated thread and some comments may be shown as answers.

Handle message dialog from webpage

4 Answers 123 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Chunks
Top achievements
Rank 1
Chunks asked on 11 Jun 2013, 09:39 PM
Hi All,

In our application, we have a dialog which pops up when a user tries to close the browser without logging out using the official link. We seems to have no control over it and you can't see this in DOm. It just locks the browser control and give you two options :

Leave this Page

Stay on this page


how should I go about handling this use-case, if suppose I intend to click on "Leave this Page"

Thanks in advance!

4 Answers, 1 is accepted

Sort by
0
Mario
Telerik team
answered on 14 Jun 2013, 03:46 PM
Hello Aakash,

Thank you for your question.

This type of dialog is considered to be an OnBeforeUnload event (public example site).

You will first need to add a using statement for 'ArtOfTest.WebAii.Win32.Dialogs'.

Please see code sample below which works against the public site mentioned above:

OnBeforeUnloadDialog dialog = OnBeforeUnloadDialog.CreateOnBeforeUnloadDialog(ActiveBrowser, DialogButton.OK);
Manager.DialogMonitor.AddDialog(dialog);
HtmlAnchor link = Find.ByExpression<HtmlAnchor>("innertext=Click here to navigate to www.microsoft.com.");
link.MouseClick();
dialog.WaitUntilHandled(10000);

Please let me know whether you have any additional questions.

Regards,
Mario
Telerik
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Chunks
Top achievements
Rank 1
answered on 18 Jun 2013, 09:14 PM
This works, Thank you, Mario!!
0
James
Top achievements
Rank 1
answered on 09 Oct 2013, 05:55 AM
Hi Mario,

We are Telerik's customer for last 4 years and use Rad Controls in our web application. We also use WebAii's testing framework for test automation.

When automated test case load application in the browser and then attempt to close the browser after completing test, browser shows dialog with 2 options "Leave this page" and "Stay on this page". 

I want automated test case to choose "Leave this page" option. 

I use below code, however it does not seem to choose "Leave this page" and close the active browser. 

OnBeforeUnloadDialog dialog = OnBeforeUnloadDialog.CreateOnBeforeUnloadDialog(ActiveBrowser, DialogButton.OK);
Manager.DialogMonitor.AddDialog(dialog);
Manager.DialogMonitor.Start();
ActiveBrowser.Close();
dialog.WaitUntilHandled(10000);


Could you please advice me how to handle this dialog and choose "Leave this page" to close the active browser?
0
Ivaylo
Telerik team
answered on 14 Oct 2013, 07:41 AM
Hello James,

Please let me interject into this ticket since Mario is out of the office today.
Could you please try placing the following code where this dialog appears:

this.Manager.Settings.UnexpectedDialogAction = UnexpectedDialogAction.HandleAndContinue;

Hope this helps.

Regards,
Ivaylo
Telerik
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Chunks
Top achievements
Rank 1
Answers by
Mario
Telerik team
Chunks
Top achievements
Rank 1
James
Top achievements
Rank 1
Ivaylo
Telerik team
Share this question
or