How can I generate and get the "idx" attribute from a unique UiElement that doesn't have one?

For context, I’m using the Web Application: Whatsapp Web.

To identify the latest message element from a given chat, you can’t use the text or “aaname” attribute because that’s what you want to get in the first place. If you remove the “aaname” attribute, an “idx” attribute is generated, because the remaining attributes are not sufficient to identify a given message from the rest, which now have identical attributes.

To get the latest message element, I instead had to use an anchor base, which looked like this:


So far so good.

The latest message is saved to a UiElement variable, which now contains all the attributes of that message element, including the “aaname” attribute. I can now get its text by using messageElement.Get(“aaname”).ToString

But since the “aaname” aatribute is now present, the “idx” attribute is no longer necessary to identify that message from all the others, and therefore I cannot get its value with the following expression: messageElement.Get(“idx”).ToString. It just returns a null value, because the message is unique, now that the “aaname” attribute is included.

Is there a way to get an UiElement variable’s idx when compared to other elements of the same class, but ignoring the “aaname” attribute?

Hi,

As you can see in the post bellow, idx seems like to come into play of your other attribute of your selector return more than one element.

You could however use a Find Children activity with a filter not including your aaname (so only classname) and use this type of expression under based out of FindIndex on the output of Find Children, it should return your the same value as the idx.

Cint(elems.ToList.FindIndex(Function(e) e.Get("aaname").toString = "youraaname"))+1

Let me know if you need more explanation/details

Cheers

2 Likes

Sorry for the late reply. I got the ancestor element that contained all the child text message elements; but I don’t really know how to use the filter property of the find children activity. This is what I’ve got so far:

Hi,

The filter property should contain a selector line like on the screenshot bellow, the previous expression will permit you to access the idx value (you can for example assign it to an integer).

image

The property “selector” will indicate the scope where you will look for Childrens, that might be better than the ancestor

Cheers

1 Like

Oh, I see. Thanks!