How to use xpath in selector

I want to retrieve this xpath so I can use it as a dynamic selector.


I have created a string variable with this xpath assigned to it.

  1. How to pass this xpath to UIPath mobile selector dynamically?
    image

Hi,

i think this can help you

Thanks for the quick response. I have already created a variable with the xpath selector. However, how can I use this variable as dynamic selector?

Yes like this:
image

Its not working
Does this work with mobile automation selector?

Assuming you are using UIAutomation 20.10.x, firstly you need to create the variable and give it a default value before using it within the selector. Only the attribute’s value can be a variable, not the entire attribute_name=attribute _value pair.
Example:

If you upgrade to 20.12 preview, you will get a contextual menu at right click, to define the variable and its default, prior using it.

I’m using version 20.10.12.
Can you please elaborate, I’ve added a screenshot for your reference.

Hi @mounir.mohsen .
You cannot use xpath selectors with our solution. There are technical reasons for that, especially performance related.
At design time, in MDM, we generate selectors.
Those are in turn transformed at runtime into UIAutomator native calls.

But why do you need an xpath selector ?

Thanks,
Bogdan

2 Likes

Hello @Bogdan_Cucosel,
Thanks for the clarification, I was trying to use the xpath from appium as a dynamic selector for identifying a set of targets as shown in the snapshot.


so that I can loop on each target.

Appreciate your help.

1 Like

Ok, if you are in a While or For activity and try to use the {{variableName}} syntax, then there is a bug.
This has been solved on the 20.10.6 package version. This is already available on our official feed.
Try to get that version please and let me know.

1 Like

I have updated the package. However, its still not working. I don’t know if it’s syntax’s or not.
I’ve tried setting the variable ID = 8,

image

It works when I use a specific idx=‘8’
image

when I try to select the target using: attribute name = ‘{{variable}}’, no match is found

image

Ok, it seems that we have one more bug. I think the design time is still broken.
Could you please try the runtime ?
I mean, have the selector with idx={{ID}} and run the project just to confirm that it works at runtime ?

Thanks,
Bogdan

1 Like

Thanks a ton, It works fine in runtime, I think the design time still have some issues.
Do you know how to get the idx attribute from the get attribute activity. its not listed in the dropdown menu, but I have seen someone suggesting to write “idx”
image

Thanks for the confirmation, I will add an issue to fix the design time in our next release.

About the idx attribute. You cannot retrieve that attribute since that is not a native attribute to any technology. There is no native idx attribute in Android UIAutomator nor XCUITest, nor in html dom for that matter. That is because idx is relative to something. For us for example it means that we take the selector where we applied idx and apply it to it’s parent selector and return the element at position idx, if any.

Indexes are very brittle and I would try to avoid them if possible.
Maybe you can find a way to leverage anchors ? Or maybe some text specific to the element you are targeting ?

Thanks,
Bogdan

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.