Forum Discussion

rlounsbury's avatar
rlounsbury
Occasional Contributor
14 years ago

Test script cannot find Alert boxes

We are working on writing TestComplete scripts to test a large web app which is in ongoing development.  In the app, there are a number of areas which pop up an alert box to, for example, confirm that the user really wants to delete an entry.  When I record a script, TestComplete records something like:




iexplore = Aliases.iexplore;

iexplore.dlgMessageFromWebpage.btnOK.ClickButton();


However when I run the recorded script it shows an error stating "ambiguous recognition of tested object".  If I use the find method as follows:


  

  var confirmDlg = Aliases.iexplore.Find(["MappedName"],

                        ["*iexplore.dlgMessageFromWebpage"],

                        10);

  confirmDlg.Wait();

  var okButton = confirmDlg.Find(["MappedName"],

                        ["*dlgMessageFromWebpage.btnOK"],

                        10);

  okButton.Click();




The confirmDlg.Wait() line causes an "object does not exist" error.  I have also tried finding the object by passing "Aliases.iexplore.dlgMessageFromWebpage" as the MappedName.



Can anyone tell me the proper way to reference this dialog so that I can access the OK button on it?



TIA,

Ron L.


  • rlounsbury's avatar
    rlounsbury
    Occasional Contributor
    Robert



    We tried the same script on a system with IE8 this morning, and IE8 exhibits the same problem.  Does this suggest any other possibilities to you?  I am hesitant to change registry settings since we plan on running the tests using TestExecute at a later date and I don't want to have to keep track of configuration issues there.



    Thank you,

    Ron L
  • rlounsbury's avatar
    rlounsbury
    Occasional Contributor
    Robert



    We believe we have found the solution.  The issue appears to have been twofold: IE8 & IE9 opened the alert window in a new process, so our alias to iexplore didn't find the proper process, and the caption for the window was different in IE6 than it was in IE8/9.  The following code appears to resolve both problems:



         var caption

         if (getBrowserVersion() == 6) {

              caption = "Microsoft Internet Explorer";

         } else if (getBrowserVersion() == 8) {

              vcaption = "Message from webpage";

         }

         var dlg = Sys.Find(["WndClass", "WndCaption"], ["#32770", caption], 10);

         Delay(500);

         var btn = dlg.Find(["WndClass", "WndCaption"], ["Button", "OK"], 5);

         btn.Click();


    Where getBrowserVersion is defined as:


    // The purpose of this function is to determine the version of the browser

    // to be used when opening up a dialog box.

    // Valid return values will be either 6, 8 or 9.  0 will be returned for an unidentified version

    function getBrowserVersion()

    {

     

      var verstring = aqString.substring(Aliases.iexplore.FileVersionInfo, 0, 1);

     


      if (verstring == "9") {

        return 9;

      } else if (verstring == "8") {

        return 8;

      }

      else if (verstring == "6") {

        return 6;

      } 

      else {

        return 0;

      }  




    Thanks for your help,

    Ron L

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    What are the properties being mapped to identify the box and the values set on them?



    Attached is a screenshot showing how I mapped the same item
  • rlounsbury's avatar
    rlounsbury
    Occasional Contributor
    Robert



    Thank you for the response.  I changed my code to the following:




      var confirmDlg = Aliases.iexplore.Find(["WndClass", "WndCaption"],

                            ["#32770", "Message from webpage"],

                            10);

      confirmDlg.Wait();


    and the confirmDlg.Wait(); line still causes an error stating "The object does not exist..."



    Do you have any other suggestions?



    Thank you,

    Ron L


  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    I'm running on Windows XP... the dialog box may have different class and caption than mine if you're running on Windows 7.  That's why I asked what your mapping is saying about the dialog.  How is it mapped in your NameMapping/Aliases tree?  



    Also, try using FindChild instead of Find.



    The point is that your methodology for finding the object isn't necessarily flawed... just that your expectation of what criteria is being used to find it may be the source of the mistake.  Also, before you call any functions or methods off the object you are searching for, it's a best practice to check to see if it Exists with a "if Exists then" check or something.
  • rlounsbury's avatar
    rlounsbury
    Occasional Contributor
    Robert



    Sorry, I didn't understand what you were asking for before.  I have attached a screen shot of the ObjectSpy dialog of the dialog.



    Thank you,

    Ron L
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Okay, it's obvious from that screenshot that the object exists (note the Exists property).



    So... my guess is that the problem is not in finding the object but in the timing of when the object appears.



    so, going back to your original code, here's how I would change it.



      var confirmDlg = Aliases.iexplore.WaitAliasChild("dlgMessageFromWebPage", 60000)

    if (confirmDlg.Exists)

    {

      var okButton = confirmDlg.btnOK

      okButton.Click(); 

    }




    You already have the object mapped so you don't need to "find" it or identify it in any way.  What you need to do instead is wait until the object Exists before proceeding.  The above code will wait a maximum of 60 seconds before proceeding.  If the dialog box appears within those 60 seconds, the WaitAliasChild method will return the object.  If after 60 seconds the dialog object does not appear, a "stub" object with Exists = false will be returned.



    The conversation about your mapping has to do with the error about "ambiguous recognition".  What that message means is that TestComplete found potentially multiple objects that could all be identified using the same criteria.  What I would like to see is the following similar screenshot to help you figure out how to solve that problem.  What I have posted should be sufficient to identify your dialog... ASSUMING it is the only instance of that dialog in memory.  If you have multiple dialogs open in internet explorer at the time that you hit this section of code, you'll get that "ambiguous recognition" error.
  • rlounsbury's avatar
    rlounsbury
    Occasional Contributor
    Robert



    I tried your suggestion but it didn't fare any better.  I have confirmed (multiple times) that there is only one instance of the dialog at the time of testing.  A coworker looked at it and when we changed it to the following code it works with IE 6 on XP but still does NOT work with IE 9 on Win 7



         Delay(500);


         //var confirmDlg = Aliases.iexplore.WaitAliasChild("dlgMessageFromWebPage", 60000)

         var confirmDlg = iexplore.Find(["WndCaption", "WndClass"], ["OK", "Button"], 10);

         if (confirmDlg.Exists) {

                 confirmDlg.Click();

         } else {

         Log.Error("Could not find the Confirmation dialog");

         }



    So it appears that this is being introduced by either IE 9 or Win 7.  Do you have any similarly configured systems you can test against?



    Thank you,

    Ron L

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    I do not know for certain, but it's possible that, since it is IE 9, the message dialog may be under a completely different iexplore process.  Take a look at your object browser and see how many iexplore processes are there and which one has the dialog associated with it.



    This does not necessarily guarentee that changing your mapping to point to the right process will fix it.  If this is the case, my best suggestion to fix it is to adjust the registry for the TabProcGrowth key to only spawn 1 iexplore process.  I think there's an MSDN article on it.