Forum Discussion

JackSparrow's avatar
JackSparrow
Frequent Contributor
7 years ago

How to wait for an object using for loop [python]

Hi all ,

My application is an desktop application , while execution i need to wait for an window object and sometimes it may take long time to load , so I thought of using for loop with iteration. where waiting time can be incremented untill object loads . I tried but am not able to do it in Python ,can anyone help me out .Other than using delay .

7 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    I don't know about Python scripting... but here's how I do it in JavaScript... you should be able to translate:

     

    var counter = 0;
    var maxCount = 60;
    while ((!Aliases.MyApp.WaitAliasChild('myObject', 500).Exists) && (counter < maxCount)){
        counter++;
    }

    This will wait max 30 seconds (500 ms executed 60 times = 30000ms). Convert this to a function where you pass in the parent object, the alias name, and a max wait time and you've got a nice little routine.

    • JackSparrow's avatar
      JackSparrow
      Frequent Contributor
      In ur routine ur waiting for the child object ?
      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        JackSparrow wrote:
        In ur routine ur waiting for the child object ?

        Correct... that's what the WaitAliasChild does... it waits for the immediate Alias child object of the indicated parent (in my example, Aliases.Myapp) with the indicated name.  There are other "Wait" methods as well that work similarly where you wait for some child object of the parent.

         

        Another way of doing it, if you aren't looking for the immediate child object, is to use some sort of "Find" method... search for the object with a set of parameters, check to see if the result comes back as the object, pause, repeat... something like...

         

        var objectToFind;
        var counter;
        var maxCount = 60;
        objectToFind = Aliases.MyApp.FindChild('ObjectType|ObjectLabel','Button|OK', 5);
        while ((!objectToFind.Exists) && (counter < maxCount)){
            aqUtils.Delay(500);
            counter++;
            objectToFind = Aliases.MyApp.FindChild('ObjectType|ObjectLabel','Button|OK', 5);
        }

        The above has, effectively, the same general effect of waiting 30 seconds for an object to exist.  It searchs for the object... if the object is not found and we haven't hit our max loop counter, wait 500 ms, increment the counter, and repeat the search.