UIClick second element by identical name

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

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

UIClick second element by identical name

Post by Warren » Wed Oct 25, 2017 11:34 pm

I've got a page that always has two UI elements with the same name. If I say UIClick>elementName, it always clicks on the one I don't want. I assume this is because it is listed first in UI accessibility list If this is the case, I want to click on the one that is always listed second.

I've been re-reading through the documentation, but haven't found a solution yet. Do I need to do some sort of list into an array like the position fucntions return X_0, X_1 and then somehow refer to the second indexed item in the array (not quite sure what combo of commands that would be), or maybe use the UIAccessibile function to return a unique handle, or is there a simpler built in way I'm missing along the lines of

UIClick>elementName_2

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

Re: UIClick second element by identical name

Post by Marcus Tettmar » Thu Oct 26, 2017 11:02 am

I'm afraid there's no way to do this at present - it will always stop at first match. Sorry. Are both items inside the same parent container? You may find you can drill down further in the window hierarchy? If not could you UIFocus and then Press Tab the required number of times to get to the second item? I tend to use keystrokes this way as it mirrors how the user works. As long as you have a way to get to a known starting point you then know how many times you need to tab to get where you want. Or UIFocus the element just before the one you want and then it's just one Press Tab.

I will investigate whether we can add an optional second parameter which takes the index, so that in these situations you could tell it you want the second match, and so on.
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: UIClick second element by identical name

Post by Warren » Thu Oct 26, 2017 3:31 pm

I have the same issue on multiple sites. Some are in the same child window, others look like I may be able to use the window hierarchy, though I'm not quite sure how I'd do that yet. I've been trying the tab solution, and it works in some cases. i'm more trying to futureproof the script against site changes.

What I really need, though, and maybe there is a way to do this... is a way to refer to something according to it's relation to another element. For instance, if there are 20 play buttons, click the one that relates to a particular field of text, or the third one in a given list, etc. That would still work even with most fairly significant site changes. I suppose that's an extension of the idea of using the window hierarchy.

This has brought up a related question: There are often little text boxes (not sure what they're callled... tooltips maybe?) that pop up when you hover over something. What should I be looking for to be able to use the text associated with hovering over that element as a way to select the element?

For instance, UI element name just says "b", but if I hover over it, it says "Pause". Is there a standard way to refer to that button via the "Pause" moniker?

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

Re: UIClick second element by identical name

Post by Marcus Tettmar » Mon Oct 30, 2017 2:23 pm

I'm afraid there's no way to do this.

What we're dealing with here is having to make the most of Windows guess work. If an app has not explicitly been made "accessible" by the developers then Windows creates the accessible tree based on positions of labels and so on. In this case it can be hit and miss as to how useful it can be. You can see the info you have to work with using the View System Windows Tool, right click on an object and select Accessible Object Tree. If you can work with it great, if not, I'm afraid you'll have to find other methods.
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: UIClick second element by identical name

Post by Warren » Wed Nov 01, 2017 3:46 pm

I've been trying to find alternative ways to do this. Some sites, it works to select another element as a reference point, and tab to the desired element from there, so thanks for that tip.

On some sites, though, UIClick shifts the tab focus to an element, but UISelect and UIFocus do not, so I can't use one element as a reference to then tab to another since the tab focus is always still on the last item that was actually clicked.

It's looking like a dead end for those sites, but just wanted to check to see if there's any other way to force tab focus on a named element that I might be missing.

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

Re: UIClick second element by identical name

Post by Marcus Tettmar » Thu Nov 02, 2017 10:26 am

You say "page". Are we talking about web pages? In which case you are probably better off with the IE functions, which will let you identify elements via the HTML names/attributes. Or do I remember some reason why IE is out of the question?
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: UIClick second element by identical name

Post by Warren » Fri Nov 03, 2017 3:36 pm

Yeah, webpage. And yes, I need to use a custom Chromium build. Once I've got the Chrome scripts worked out, I'll adapt as necessary to port scripts over to a custom Firefox fork as well.

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