Forum Discussion

emily_m's avatar
emily_m
New Contributor
2 years ago

WaitMethod in a loop

 

My function should wait for the app to be ready after all the loadings are gone. Since the loading window appears and disappears several times, I tried using WaitMethod in a loop. However, sometimes, when the window is up, WaitChild does not recognize it from the second iteration. Vice versa, sometimes, while the loading bar is gone, WaitChild seems to be recognized. Thus, I thought it might be related to object being cached, so I put Sys.Refresh. - But it didn't work.

 

My initial code looks like this:

 

do {
  Sys.Refresh()
  var loading = Sys.Process("App").WaitChild(`WPFObject("LoadingBar")`, 20000);
  if (loading.Exists) {
     loading.WaitProperty("Exists", false, 30000);
  } else {
     if (...) {
       ready = true;
     }
  }
} while(!ready);

 

1. Any ideas why it doesn't work?

2. Does WaitChild or WaitProperty refresh the object tree?

 

Interestingly, when I set "loading" to WaitChild function's returned object only once and used WaitProperty in a loop, and it successfully recognized the object and its status accurately in every iteration. And depending on whether the loading screen is showing at the moment or not, variable.WaitProperty in a loop works differently.

- If it shows, it will wait for the property to have the specified value until it reaches the given time.

- If not (if the loading doesn't even exist in the object tree), it will try to find the object for 10 seconds (I guess default object recognition attempt).

 

It made me wonder:

3.  WaitProperty from Variable that holds WaitChild expression returning its searched object or stub object - Does it always search for the object first (for max 10 seconds by default) and then WaitProperty gets executed? 

 

 

// save Loading object only once
var loading = Sys.Process("App").WaitChild(`WPFObject("LoadingBar")`, 20000);
loading.Exists && loading.WaitProperty("Exists", false, 30000);

do {
  // A. if the loading window doesn't exist at its execution, it will first try to find the obejct for 10 seconds.
  // B. If it shows, it will wait for the Exists property to disppear for 5 seconds
  if (loading.WaitProperty("Exists", false, 5000) {
    ready = true;
  }
} while(!ready);

 

 

I am really curious what's going on behind WaitMethod and what I observed is correct.