Using a variable in a selector

Hi,

I’m trying to create an IF where a person is removed from an overview based on the name. The overview is on a website and in order to remove the person, a delete button must be clicked next to the name.
The people that have to be removed are stored in a variable. So the variable has to be found, then if it is found, the cross must be clicked. So my question is: how do I ensure that Uipath first finds the correct line with the name and then clicks on the cross next to this name.

Try using selector with a relative text. i.e if your name is next to the x sign.
Then make your relate text dynamic by using the names from the variable if many in a for loop.

Steps:

  1. Use a click activity
  2. Indicate the element on the screen
  3. Now edit the selector using UI Explorer
  4. On UI Explorer top right you have an option to use relative text

image

  1. Indicate the text which is the name
  2. Your selector should now be updated with the new value
  3. Edit the value and add your dynamic variable

Hope this helps

Hello.

From my experience, you can’t use the Selector Editor to add a variable into the selector. You need to use the Expression editor. Basically, your selector is stored as a string, so you want to edit it while it’s in that format (ie surrounded by quotations)

If you click inside the Selector property, you will see that it is a string surrounded by quotes:
image

So edit that string. One trick you can do is remove the “<” character first, then when you click the “…” edit button, it will open the Expression Editor to make the edit much easier (remember to place the character you removed back in there though).

The other half is identifying the attribute that contains the words you want to replace with a variable.

Your selector might end up looking like this:

"<webctrl aaname='*"+variable+"*' />"

where I used a wildcard also to make it more robust.

Anyway, I hope I am clear and this helps.

Regards.

Thank you. I solved the problem by using your method!

1 Like

Hi everyone,

You can now define your variables for selectors directly in Studio.

Please check our official documentation here:

As well as this short tutorial on our Forum:

I took the liberty to change the solution flag to this post to let our users know about this feature :slight_smile:
Old solution post is this one.

1 Like