How to wait for or check existence of UI elements

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
Warren
Pro Scripter
Posts: 83
Joined: Sun Oct 08, 2017 11:57 pm

How to wait for or check existence of UI elements

Post by Warren » Mon Oct 16, 2017 7:31 pm

There are a couple of commands that are easy to perform with windows, but don't seem to have equivalent commands for UI elements.

How do I achieve the following for UI elements?

1) WaitWindowOpen> command equivalent that waits for UI element to appear (sometimes takes longer than window)

2) IfWindowOpen> command equivalent that checks to see if a UI element exists

They seem quite straight forward, but if there is a command that just does either of these things, I haven't found it despite reading through all the docs multiple times, and all attempts to cobble the functionality together have proved more problematic than expected. What's the simplest way to achieve these 2 basic checks?

Warren
Pro Scripter
Posts: 83
Joined: Sun Oct 08, 2017 11:57 pm

Re: How to wait for or check existence of UI elements

Post by Warren » Thu Oct 19, 2017 1:55 am

I've been working with this for another couple of days now, and it's still unresolved. I have a number of scripts where I'm essentially working around my inability to check for or wait for UI elements. I can use static wait times, or wait for images instead, but it's not always the same.

Is there some way to do these things that I'm missing?

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: How to wait for or check existence of UI elements

Post by Marcus Tettmar » Thu Oct 19, 2017 8:59 am

You could use UIAccessibleList in a loop. UIAccessibleList gives you all the accessible UI objects in a window. So you could call UIAccessibleList then do a substring search or RegEx against it to see if the object you are waiting for is there. If not, you keep looping. Would that work?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Warren
Pro Scripter
Posts: 83
Joined: Sun Oct 08, 2017 11:57 pm

Re: How to wait for or check existence of UI elements

Post by Warren » Thu Oct 19, 2017 1:27 pm

I guess so. I think I read on here somewhere that that's essentially what WaitWindowOpen is, right? A loop that just keeps reading the available windows and looping back if not found until the timeout?

Sounds more or less like what I was trying to cobble together. Either I was going crazy, or the handles were changing, and with window names that change depending on the page displayed in that tab, it was getting frustrating, but still seemed like there must be a way to do it.

I'll try that and read up on the string parsing functions.

Is it best to put a distinct time interval in such a loop, or does the WIN_SLEEP assist in such a case with no defined wait? Asking because I'm using shared core kvm vps, and need to keep an eye on cpu cycles.

Warren
Pro Scripter
Posts: 83
Joined: Sun Oct 08, 2017 11:57 pm

Re: How to wait for or check existence of UI elements

Post by Warren » Thu Oct 19, 2017 8:30 pm

For the IF EXISTS part, I've worked out something like:

Code: Select all

SRT>clickIfElement
   Let>elementName=clickIfElement_var_1
   Let>windowName=clickIfElement_var_2

   UIPos>windowName,elementName,elementPOS

   IF>elementPos<>{""}
      UIClick>windowName,elementName
   ENDIF
END>clickIfElement

GoSub>clickIfElement,LOG IN,Chrome*
It seems to be working for now, but I notice that the UIAccessibleList returns elements from all tabs in the browser. I'm assuming this will be a problem since there may be a "LOG IN" element on another tab.

Is there a way to limit the search results for UIPos, UIAccessibleList, etc to only the current tab to make sure I'm not getting false positives for elements on other tabs?

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: How to wait for or check existence of UI elements

Post by Marcus Tettmar » Fri Oct 20, 2017 11:49 am

Yes, you can use the handle instead of the window title, so using FindObject you could narrow down on the window you want to pull from and use that instead of the main parent.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Marcus Tettmar
Site Admin
Posts: 7378
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: How to wait for or check existence of UI elements

Post by Marcus Tettmar » Fri Oct 20, 2017 11:50 am

Yes, you can use the handle instead of the window title, so using FindObject you could narrow down on the window you want to pull from and use that instead of the main parent.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts