Forum Discussion
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.
thanks for the code but , i want to implement without delay method .
- baxatob7 years agoCommunity Hero
You can't avoid a delay, if you need to wait for something.
tristaanogre has advised a nice and flexible method.
def wait_for_something_exists(something, timeout): counter = 0 while not something.Exists and c < timeout: aqUtils.Delay(1000) # or time.sleep(1) counter += 1
- JackSparrow7 years agoFrequent Contributor
Thanks baxatob tristaanogre will try and come back
- tristaanogre7 years agoEsteemed Contributor
JackSparrow wrote:
thanks for the code but , i want to implement without delay method .
The original solution I presented with "WaitAliasChild" doesn't use the delay method because the "wait time" is built in to the method. But if you don't want to find the object that is an alias or a direct child object (there are a variety of "waitNNN" methods but they all require the object to be waited for to be a direct child of a parent), then the while loop using "FindChild" is your best bet... and you need to use a delay. The way I have it written, the max wait time can be parameterized as can the properties and so forth. But because the FindChild method does not have a built in delay, you need to incorporate that delay somehow to wait for the object to return.
As baxatob pointed out, you need to have that delay somehow. The Best Practice of avoiding hardcoded "sleeps" is a good one... but that applies primarily to just dropping in delays without smart loops like what baxatob or I wrote... both of the sections of code we presented will not wait a fixed amount of time (there is a max time) so it is "smart" code in that respect.
Related Content
- 3 years agoIuliaVascan
- 6 years agosriram_sig
- 2 years agolalit_singh
Recent Discussions
- 3 hours agoSubhraDas