Alert Dialog handler in popup window is giving error on click of button in WebAii

28 posts, 1 answers
  1. Hemashree
    Hemashree avatar
    9 posts
    Member since:
    Jul 2012

    Posted 25 Oct 2011 Link to this post

    The pop up window exists with alert dialog with OK and Cancel button.

    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





  2. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 27 Oct 2011 Link to this post

    Hi Hemashree,

    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.

    Greetings,
    Anthony
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Hemashree
    Hemashree avatar
    9 posts
    Member since:
    Jul 2012

    Posted 28 Oct 2011 Link to this post

    HI Anthony,

    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



     

  4. Answer
    Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 28 Oct 2011 Link to this post

    Hello 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.
  5. Hemashree
    Hemashree avatar
    9 posts
    Member since:
    Jul 2012

    Posted 02 Nov 2011 Link to this post

    It Worked!!!!!!!!!!!!!!!!!
    Thanks a lot for the help...................


    Thanks and Regards,
    Hemashree
  6. Srinivasan
    Srinivasan avatar
    15 posts
    Member since:
    Jun 2015

    Posted 10 Jun 2015 Link to this post

    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

  7. Srinivasan
    Srinivasan avatar
    15 posts
    Member since:
    Jun 2015

    Posted 10 Jun 2015 Link to this post

    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...

  8. Srinivasan
    Srinivasan avatar
    15 posts
    Member since:
    Jun 2015

    Posted 12 Jun 2015 Link to this post

    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

  9. Srinivasan
    Srinivasan avatar
    15 posts
    Member since:
    Jun 2015

    Posted 15 Jun 2015 Link to this post

    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.

  10. Ivaylo
    Admin
    Ivaylo avatar
    750 posts

    Posted 18 Jun 2015 Link to this post

    Hello,

    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
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  11. Srinivasan
    Srinivasan avatar
    15 posts
    Member since:
    Jun 2015

    Posted 18 Jun 2015 Link to this post

    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.

  12. Boyan Boev
    Admin
    Boyan Boev avatar
    1040 posts

    Posted 23 Jun 2015 Link to this post

    Hello Srinivasan,

    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
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  13. Srinivasan
    Srinivasan avatar
    15 posts
    Member since:
    Jun 2015

    Posted 24 Jun 2015 Link to this post

    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

  14. Srinivasan
    Srinivasan avatar
    15 posts
    Member since:
    Jun 2015

    Posted 24 Jun 2015 Link to this post

    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

  15. Srinivasan
    Srinivasan avatar
    15 posts
    Member since:
    Jun 2015

    Posted 24 Jun 2015 Link to this post

    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

  16. Boyan Boev
    Admin
    Boyan Boev avatar
    1040 posts

    Posted 29 Jun 2015 Link to this post

    Hi Srinivasan,

    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
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  17. Srinivasan
    Srinivasan avatar
    15 posts
    Member since:
    Jun 2015

    Posted 10 Jul 2015 in reply to Boyan Boev Link to this post

    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.

  18. Boyan Boev
    Admin
    Boyan Boev avatar
    1040 posts

    Posted 15 Jul 2015 Link to this post

    Hi Srinvasan,

    Here is the code which handle an alert dialog.

    Please try that out and let me know the results.

    Regards,
    Boyan Boev
    Telerik
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  19. Srinivasan
    Srinivasan avatar
    15 posts
    Member since:
    Jun 2015

    Posted 15 Jul 2015 in reply to Boyan Boev Link to this post

    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

  20. Boyan Boev
    Admin
    Boyan Boev avatar
    1040 posts

    Posted 20 Jul 2015 Link to this post

    Hi Srinivasan,

    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
    element.click();
     
    // 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
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  21. Srinivasan
    Srinivasan avatar
    15 posts
    Member since:
    Jun 2015

    Posted 20 Jul 2015 in reply to Boyan Boev Link to this post

    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

  22. Boyan Boev
    Admin
    Boyan Boev avatar
    1040 posts

    Posted 23 Jul 2015 Link to this post

    Hi Srinivasan,

    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
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  23. Srinivasan
    Srinivasan avatar
    15 posts
    Member since:
    Jun 2015

    Posted 23 Jul 2015 in reply to Boyan Boev Link to this post

    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

  24. Boyan Boev
    Admin
    Boyan Boev avatar
    1040 posts

    Posted 27 Jul 2015 Link to this post

    Hello Srinivasan,

    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
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  25. dan
    dan avatar
    27 posts
    Member since:
    Jun 2016

    Posted 15 Sep in reply to Anthony Link to this post

    The links are broken
  26. Boyan Boev
    Admin
    Boyan Boev avatar
    1040 posts

    Posted 20 Sep Link to this post

    Hi Dan,

    Here is the correct link:

    Handling HTML Pop ups

    Hope that helps.

    Regards,
    Boyan Boev
    Telerik by Progress
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
  27. dan
    dan avatar
    27 posts
    Member since:
    Jun 2016

    Posted 22 Sep in reply to Boyan Boev Link to this post

    Thanks!
  28. Boyan Boev
    Admin
    Boyan Boev avatar
    1040 posts

    Posted 26 Sep Link to this post

    Hello Dan,

    You are most welcome.

    If you need any additional information please let us know.

    Regards,
    Boyan Boev
    Telerik by Progress
     
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
     
Back to Top