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?
How to wait for or check existence of UI elements
Moderators: Dorian (MJT support), JRL
Re: How to wait for or check existence of UI elements
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?
Is there some way to do these things that I'm missing?
- Marcus Tettmar
- Site Admin
- Posts: 7380
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: How to wait for or check existence of UI elements
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Re: How to wait for or check existence of UI elements
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.
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.
Re: How to wait for or check existence of UI elements
For the IF EXISTS part, I've worked out something like:
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?
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*
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?
- Marcus Tettmar
- Site Admin
- Posts: 7380
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: How to wait for or check existence of UI elements
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Marcus Tettmar
- Site Admin
- Posts: 7380
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: How to wait for or check existence of UI elements
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?