Javascript dialog handling

2 posts, 0 answers
  1. Saket
    Saket avatar
    22 posts
    Member since:
    Sep 2011

    Posted 15 Nov 2011 Link to this post

    I am writing a test script using MS test and Webaii in which i have to fill in a application form.On the save of the form the system checks for the mandatory feilds if not prompts a javascript alert message that the mandatory feilds a,b,c are not filled.
    I need to capture and log this step in my code test
    I did the floowing to try capture the script alert

               Settings.Current.UnexpectedDialogAction = UnexpectedDialogAction.HandleAndFailTest;
    // Attempted to check if the line below captures the dialog
               int counter= manager.DialogMonitor.Dialogs.Count;
    //This actually adds a dialog --- not what is needed

                manager.DialogMonitor.AddDialog(new AlertDialog(manager.ActiveBrowser,DialogButton.OK));

    Any help appreciated

  2. Stoich
    Stoich avatar
    1 posts

    Posted 18 Nov 2011 Link to this post

    Hello Saket,
        here's a code sample that demonstrates how to handle a Javascript dialog in code:
    // Launch an instance of the browser
                // Please make sure you call the current dialog handler before the dialog actually appears on the screen!
                // Handle 'Alert' dialog.
                AlertDialog alertDialog = new AlertDialog(ActiveBrowser, DialogButton.OK);
                // Navigate to : ''
                // Click 'Button'
                FrameInfo fInf = new FrameInfo("", "view", "", "filename=tryjs_alert", 1, false, false);
                ArtOfTest.WebAii.Core.Browser t1_frame = ActiveBrowser.Frames[fInf];
                t1_frame.Find.ByExpression<HtmlInputButton>("type=button", "tagname=input").Click();
                // Wait Until Dialog is Handled.

    This code sample handles the dialog in the following demo page:

    The sample should give you a good idea of how to handle the dialog in code.

    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Back to Top