We have written the below code to handle dialogs:
//Dialog handler code
AlertDialog altDlg = new AlertDialog(ActiveBrowser,DialogButton.OK);
Manager.DialogMonitor.AddDialog(altDlg);
Manager.DialogMonitor.Start();
//The alert dialog opens On click of below button
PfmPageManager.EditQuestionsPage.Elements.SaveTextButton.Click();
When the alert dialog opens and clicks on Ok button the pop up window closes.
Next it tries to execute this code : PfmPageManager.EditQuestionsPage.Elements.SaveTextButton.Click();
and fails here throwing Null pointer exception as this button exists in the pop up window which is already closed.
Please let me know if you have any soltuion for this.
Thanks,
Hemashree
29 Answers, 1 is accepted
I don't fully understand your scenario. After successfully closing the pop-up window, you're trying to click a button that only exists in the pop-up? Please clarify your scenario and provide the full section of code against a public site so we can fully understand the issue and see a local reproduction.
Also see our articles on Handling HTML Pop-ups and Handling JavaScript Dialogs in code.
Anthony
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
The scneario is like this :
- In the main window of the application I am opening a pop window
- I am clicking on Save button in pop up window
- The pop up window gives an alert dialog with OK and Cancel buttons
- The I am clicking on OK buttton in the Alert dialog which closes the Alert dialog and the pop up window.
- The application shows only the main window
=========================================================================================
The code below specifies the Alert dialog code and its giving error at the line marked in bold italics....
//Dialog handler code
AlertDialog altDlg = new AlertDialog(ActiveBrowser,DialogButton.OK);
Manager.DialogMonitor.AddDialog(altDlg);
Manager.DialogMonitor.Start();
//The alert dialog opens On click of below button
PfmPageManager.EditQuestionsPage.Elements.SaveTextButton.Click();
===========================================================================================
Please find the full section code below :
Manager.SetNewBrowserTracking(
true);
//Click on the Edit item context menu to open Edit Item window pop up
PfmPageManager.JobDescriptionPage.Elements.ContextMenu.EditItem.Click();
//Wait for pop up window to open
Manager.WaitForNewBrowserConnect(editItemWindowurl, true, 10000);
Assert.IsTrue(PfmPageManager.EditQuestionsPage.IsOnPage);
//Eneter vlaue in the Edit Item Text box
PfmPageManager.EditQuestionsPage.Operations.InputText(editedQuestion);
//Setup Alert Dialog Handler
AlertDialog altDlg = new AlertDialog(ActiveBrowser,DialogButton.OK);
Manager.DialogMonitor.AddDialog(altDlg);
Manager.DialogMonitor.Start();
//The alert dialog opens On click of below button
PfmPageManager.EditQuestionsPage.Elements.SaveTextButton.Click();
Assert.IsFalse(PfmPageManager.EditQuestionsPage.IsOnPage);
//Verify the main window presence
Assert.IsTrue(PfmPageManager.JobDescriptionPage.IsOnPage);//Verify the edited text in Main window
Assert.IsTrue(PfmPageManager.JobDescriptionPage.Elements.JobDescriptionQuestion(editedQuestion).IsVisible()); ==========================================================================================
Please let me know if u need more info on this.
Thanks,
Hemashree
See the attached screen shot. Try invoking an HtmlControl.Click(true) so Test Studio knows this click will cause the browser window to close.
Here's the code that worked for me on a local page I created. Clicking a link on the parent page loads a popup, clicking a button on the popup displays an Alert dialog, and pressing OK on the dialog closes the popup:Manager.LaunchNewBrowser(BrowserType.FireFox);
ActiveBrowser.NavigateTo(
"c:\\html\\comma.html"
);
Manager.SetNewBrowserTracking(
true
);
HtmlAnchor confirm = Find.ByExpression<HtmlAnchor>(
"id=confirm"
);
confirm.Click();
Manager.WaitForNewBrowserConnect(
"confirm.html"
,
true
, 3000);
Manager.SetNewBrowserTracking(
false
);
Assert.IsTrue(Manager.Browsers.Count == 2);
Assert.IsTrue(ActiveBrowser.Url.Contains(
"confirm.html"
));
Manager.DialogMonitor.AddDialog(AlertDialog.CreateAlertDialog(ActiveBrowser, DialogButton.OK));
Manager.DialogMonitor.Start();
HtmlInputButton alert = Find.ByExpression<HtmlInputButton>(
"value=Show alert box"
);
alert.Click(
true
);
System.Threading.Thread.Sleep(1500);
Greetings,
Anthony
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Thanks a lot for the help...................
Thanks and Regards,
Hemashree
HI Anthony,
I am doing automation testing using Telerik framework.In that,I am facing some issue.
Steps:
1.When I click delete button in my application it open some alert popup window.
2.In that OK button and Cancel button are there.
3.Now I have to click "OK" button on the popup window using C# code for Chrome browser but not able to fetch any control and text over the alert window.How to fix this issue.
Please help me..
Thanks,
Srinivasan K
I am not able handle the popup alert window buttons in Chrome using c# code during automation test.
Let me know if you any solution for this...
Can any one please tell some solution to handle the jquery poup alert in chrome browser.How to click the buttons in that popup by means of code.
I try to find using most of the code but can't.
please let me know if anyone have solution for this issue.
Thanks,
srinivasan.k
Hello,
Anyone please tell some solution to my problem.We have an idea to buy telerik test framework.For that only we doing R&D.
Please note that the testing framework is free of charge, so you don't need to buy it, you can buy a support since when using the testing framework you are not entitled for support.
As a starting point you can check this article.
For any further issues please make sure you check the online documentation.
Regards,
Ivaylo
Telerik
Test Studio Trainings
Thanks for your Response Mr.Ivaylo.
Ok ,it may be free one.Can you tell solution for my problem.I heard that its a price one thats, why i mentioned like that.
Have you checked the article which describes how to handle popups in code?
If the issue persists please give us more detailed information so we can help you best:
1. Send us some screen shots.
2. Describe in details the problem you are experiencing.
3. Provide us with the code you are using.
Hope to hear from you soon.
Regards,
Boyan Boev
Telerik
Test Studio Trainings
Hello Boyan Boev,
1.When i click the save button without enter any data the alert window will open with Ok button.(or)When i click the delete button i will open the confirm alert window with ok and cancel button.
2.Once the alert window opened i am not to handle it using code.Can give some solution for that.
Note:I used all Alert and dialog handler code its not working.Browser:Chrome I attached the screenshot of both and the code for save button alone the other i similar to that only.
Thanks,
Srinivasan.K
Hello Boyan Boev,
Other problem is I am not able to find and select the date from Kendo Calendar using code.I attached the design code with this mail.Browser:Chrome
Thanks,
Srinivasan.k
Hello Boyan Boev,
Actually in our design we have three <body> tag.In that two for comment box which will open only when we click the comment button.Once the comment box i have to enter the text into the body tag using code.The comment box will open when i click but i am not able to find the elements inside it.Because they used everything inside the iframe.
The is like, <iframe>
#document
<body></body>
</iframe>
In this can find the iframe element but not the body.Can tell me some solution to find the body tag inside the #document and enter the text into it.
Thanks,
Srinivasan.K
Those are completely new issues. The best practice is to split separate issues in different tickets which help us better investigate and handle them in timely manner.
Let's focus on the pop up issue.
I am a little confused now. You says "i am not to handle it using code", but you using the framework. Do you use code for handling the pop up or not?
Could you please send us some screen shots.
Also send us the log from the execution.
Hope to hear from you soon.
Regards,
Boyan Boev
Telerik
Test Studio Trainings
Hello Boyan Boev,
Sorry for delay.Actually I send all the Source to You I am not having anything else.My Problem is Popup alert handing in Chrome.
Consider that you enter all the detail in any one of the Registration form without Saving you are clicking cancel at time you will get a Popup Alert "Details are not yet saved.Do you want to proceed?" with OK/Cancel button.At that time I want to find the alert and click Ok (or) Cancel button using C# code.
I am doing testing in visual studio 2010 using telerik Plugin.
Here is the code which handle an alert dialog.
Please try that out and let me know the results.
Regards,
Boyan Boev
Telerik
Test Studio Trainings
Hi Boyan Boev,
The code which you suggest is not working.
My TestCase:
1.Navigate to UserPage
2.Select user
3.Click delete
Upto this step the code is working properly.Once alert window Open I am not able to handle it.Even I used desktop controls also but not working.At this point test fails.
4.Click Ok button in Alert Window
Thanks,
Srinivasan.K
The click step which triggers the dialog should be in the coded step also as follows:
// Add an alert dialog to monitor
Manager.DialogMonitor.AddDialog(
new
AlertDialog(ActiveBrowser, DialogButton.OK));
// Given that there were not dialog attribute set, the manager will not start the monitoring.
// You need to invoke the monitoring
Manager.DialogMonitor.Start();
// The click step which triggers the dialog
// The dialog will now be automatically handled transparently in the background without any help from the test code.
Let me know if this helps.
Regards,
Boyan Boev
Telerik
Test Studio Trainings
Hi Boyan Boev,
The code which you mentioned above is not working for me.So,I attached my with this.Let know if you have any solution.
//Code:
Settings set = new Settings();
set.Web.DefaultBrowser = BrowserType.Chrome;
Manager Man = new Manager(set);
Man.Start();
//Lauchbrowser
Man.LaunchNewBrowser();
//Navigate to login page
Man.ActiveBrowser.NavigateTo("http://192.168.1.104/sit/lairdnewadmin");
Element user = Man.ActiveBrowser.Find.ById("UserName");
Man.ActiveBrowser.Actions.SetText(user, "laserbeam");
Element pwd = Man.ActiveBrowser.Find.ById("Password");
Man.ActiveBrowser.Actions.SetText(pwd, "laserbeam");
Element login = Man.ActiveBrowser.Find.ByTagIndex("button", 0);
Man.ActiveBrowser.Actions.Click(login);
Man.ActiveBrowser.WaitForUrl("http://192.168.1.104/SIT/LairdNewAdmin/UserManagement/ManageUsers", false, 10000);
//click the required page from menu bar
Element tag = Man.ActiveBrowser.Find.ByExpression("href=../Rating/Home");
Man.ActiveBrowser.Actions.Click(tag);
Man.ActiveBrowser.WaitForUrl("http://192.168.1.104/SIT/LairdNewAdmin/Rating/Home", false, 10000);
//find the delete icon for the given value
Element cel = Man.ActiveBrowser.Find.ByExpression("id=idRatingid", "TextContent=5");
int index = cel.TagNameIndex;
string tag1 = cel.TagName;
HtmlTableCell delete = Man.ActiveBrowser.Find.ByTagIndex<HtmlTableCell>(tag1, index +3);
//which is not working for my test case
Manager.Current.DialogMonitor.AddDialog(new AlertDialog(Manager.Current.ActiveBrowser, DialogButton.OK));
Manager.Current.DialogMonitor.Start();
//click the delete icon.It open the confirmation dialog box with OK/Cancel button.
delete.Click();​
//Once the dialog open the code stops at point itself.
Thanks,
Srinivasan.K
This is strange. This code works correct on my side.
Could you try replacing the AlertDialog with a ConfirmDialog. It is possible that this is not an AlertDialog.
Try out this code:
ConfirmDialog confirmDialog = ConfirmDialog.CreateConfirmDialog(ActiveBrowser, DialogButton.OK);
Manager.DialogMonitor.AddDialog(confirmDialog);
Manager.DialogMonitor.Start();
delete.Click();
confirmDialog.WaitUntilHandled(30000);
Let me know if this works.
Regards,
Boyan Boev
Telerik
Test Studio Trainings
Hi Boyan Boev,
I already tried this code,which is not working.Still the test hangs when alert opens.Onces the Alert open test does proceed futher.
Thanks,
Srinivasan.K
In order to debug this further and resolve it please grant us a direct access to that dialog so we can replicate the issue.
Let me know if this is possible.
Regards,
Boyan Boev
Telerik
Test Studio Trainings
Here is the correct link:
Handling HTML Pop ups
Hope that helps.
Regards,
Boyan Boev
Telerik by Progress
Test Studio Trainings
You are most welcome.
If you need any additional information please let us know.
Regards,
Boyan Boev
Telerik by Progress
Test Studio Trainings
Please provide further information on the context that you are experience troubles with. Which browser do you use and version of the application? Is the problem reproducible on a public facing application? Does the link to the documentation article provided does not help in your case?
Kind Regards,
Nikolay Petrov
Progress Telerik
Test Studio Trainings