Forum Discussion

jeremyt's avatar
jeremyt
Contributor
11 years ago

WaitNNN methods work the first time but fail the second?

I have tried using a couple of the WaitNNN methods (WaitChild, WaitAliasChild and WaitProperty) but in all cases it works the first time and fails the second. The object I'm waiting for is an HTML popup dialog, the first time it waits, eventually finds the object and the rest of my function finishes without issue. However when I call that same function again, this time when it gets to the WaitNNN method it waits and waits until finally I get an "Unable to obtain the item's rectange." error.  Oddly enough if I simply use a Delay the second time around, it will work without issue. It makes no sense to me, any help would be greatly appreciated!



9 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Perhaps, the problem isn't as much with the "Black" option but with the pop up itself.  What if you tried the following?



    Aliases.toolbar_Task.cmboBx_Publish.btn_Publish.Click();

    Aliases.cmbobx_popup_Publish.PublishToPdf.Click();

    Aliases.panel_PDFPublishOptions.cmboBx_Coloring.btn_Coloring.Click();

    if (Aliases.WaitAliasChild("cmbobx_popup_Coloring").Exists)

    {

    Aliases.cmbobx_popup_Coloring.WaitAliasChild("Black", 20000);

    Aliases.cmbobx_popup_Coloring[strColorOption].Click();

    }

    else Log.Warning ("Couldn't get the popup")



    Aliases.panel_PDFPublishOptions.btn_Publish.Click();




    This code hasn't been tested necessarily and may need tweaked but since there are other clicks occuring beore your waiting for "Black" that may open or close other windows (popups), you may need to populate your code with a few more "WaitAliasChild" calls to wait for those popups as well.  The "first time it works, second time it doesn't" may not, necessarily, be precisely true... I wouldn't be surprised if a "first time it doesn't" scenario pops up every now and then as well.



    Now, yet another "twist"...  you're using aliasing and such... is it possible that some of the identifiers you are using to map your different objects are somewhat variable as well between runs?  It could be not as much a problem with the WaitNNN method as it might be that you need to investigate and, potentially, tweak your namemapping scheme.



    Anywho, hope this helps.
  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Jeremy,


     


    Can you post here a sample demonstrating the way you use the methods?


     

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    That IS an odd problem.  Normally, WaitNNN should work fine.



    A possible solution (pending seeing what you post as your example as requested by Tanya), is that the problem may not be in the object that is the target of the WaitNNN method but the parent object itself.



    For example, check out the following code snippet



    function Test()

    {

    var Form1

    var Object1

    Form1 = Aliases.MyForm

    Object1 = Form1.WaitAliasChild("MyObject", 2000)

    //run some sort of test

    Object1 = Form1.WaitAliasChild("MyObject", 2000)

    }




    If the Form1 takes a while to be found or is destroyed and recreated at the "run some sort of test" segment, it is possible that the second WaitAliasChild call will fail... not because Object1 is not found but because the underlying object had not resolved yet.



    Again, this is just conjecture but it is an example of where I've run into similar problems.
  • Aliases.toolbar_Task.cmboBx_Publish.btn_Publish.Click();

    Aliases.cmbobx_popup_Publish.PublishToPdf.Click();

    Aliases.panel_PDFPublishOptions.cmboBx_Coloring.btn_Coloring.Click();

    Aliases.cmbobx_popup_Coloring.WaitAliasChild("Black", 20000);

    Aliases.cmbobx_popup_Coloring[strColorOption].Click();

    Aliases.panel_PDFPublishOptions.btn_Publish.Click();



    This works the first time but fails the second time it's ran...here is my current work around:



    Aliases.toolbar_Task.cmboBx_Publish.btn_Publish.Click();

    Aliases.cmbobx_popup_Publish.PublishToPdf.Click();

    Aliases.panel_PDFPublishOptions.cmboBx_Coloring.btn_Coloring.Click();

    if (strColorOption == "Original")  //equivelant to if (first time this method is run)

          Aliases.cmbobx_popup_Coloring.WaitAliasChild("Black", 20000);

    else

          Delay(500);

    Aliases.cmbobx_popup_Coloring[strColorOption].Click();

    Aliases.panel_PDFPublishOptions.btn_Publish.Click();
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    It all still sounds like timing issues of some sort.  Basically, what I'd suggest is that, after every call to a Click method, follow it up with a check to see if the next dialog exists before you do the next Click.  That's always a good rule of thumb if you're looking at these kinds of errors.
  • I tried the code you posted and it actually gave me even weirder results. The first time it's ran I get the "Couldn't get the popup" error, the second time it works and the third time I'm back to the "Unable to obtain the item's rectangle." error.
  • I guess what's confusing me here is why is their a timing issue the second time around but not the first time? Why does a WaitNNN method work the first time but fail the second time while simply replacing the WaitNNN method with a 500 millisecond delay on the second run fixes everything. I find this confusing because it means the object is literally found within 500ms on the second run yet if you use WaitNNN, it'll never be found. That just makes no sense to me, is my understanding of how these WaitNNN method's incorrect?



  • I don't think that's the case otherwise the 250ms delay wouldn't work right? However it does work which must mean that TC can in fact see the object.



    Basically what I think is happening is that the WaitNNN methods don't work if the object already exits. They only seem to work when you're waiting for an object to appear. To me this makes no sense, I would expect the methods to just simply look for the object and once located, proceed.