How to use variables in selectors in Studio (dynamic selectors) without string manipulation!

This tutorial will teach you how to easily use variables in your selectors. In other words, we will be making dynamic selectors without the use of the old method of concatenating strings. How cool is that! :slight_smile:

For the purpose of this tutorial, I will make 1 click in the Notepad app.

Feel free to also reference our documentation here.

Let’s begin!

1. First, we will indicate the element we want to click on. In this case, it will be File menu in Notepad:

image

This results in the following selector:
image

2. Now, let’s select the attribute value we want to change:

image

3. Let’s right click that attribute value for a bunch of options. In our case, we will select “Create Variable”:

image

4. From here, let’s give our variable a name and a default value:

image
And confirm it with Enter.
We will now have the new variable added instead of the previous property value:

image

When we Validate our selector, it should turn green:
image
There we go!

5. Let’s click OK to save our changes…

Here you can see the final workflow:

And this is how to make your selector dynamic :slight_smile:

Note 1 The variables/arguments need to be of type String or Int32. GenericValue type is not supported for the selector variables.
Note 2 The selector variable will take a default value if no other value is set in the workflow. As a result, it will throw an error if the value was not set and the default value is not set. Additionally, the Selector will use the Default value for validation at Design Time, but it will use the current value of the variable at Runtime.

If you want to give it a try, please check out this sample project here:
VariablesInSelectors.zip (13.7 KB)

24 Likes

Nice

2 Likes

@loginerror

Super. We can create dynamic selectors easily and no need to worry about syntax and all. It will be very helpful to the new users. Many people are facing issues with creating dynamic selectors and now this will be very helpful to them.

@loginerror

Is it new feature ? Will it work in all uipath Studio versions ?

2 Likes

I thinks it is in Studio for quite some time already, since 2019.4 if I’m not wrong.

3 Likes

neat! thanks for reminding me of this, had forgotten it was added!

2 Likes

I was expecting this for a long time
you are awesome @loginerror

2 Likes

Variables are available since 19.4. Arguments have been added in 19.8.

2 Likes

Thanks, it really looked good but for me it’s simply taking the variable name inside braces and not the actual value which the variable has.
Sure, I might be doing something wrong

Please make sure the scope of the variable is correct (= the activity can ‘see’ the variable). Otherwise, a small project that reproduces the issue would be appreciated :slight_smile:

1 Like

I am only seeing choose/create variable in the context menu, but in my case I am trying choose an argument, which I see as an option in your screenshot. Any settings that I need to change?

Edit: Just to be clear, I do understand that I can assign the value of the argument to a variable and accomplish the same thing, just trying to do it in the cleanest way possible.

Great post, I usually use string manipulation and I think this way takes less steps and it’s easier to read. Thank you!

2 Likes

Hi @jcarr79

Argument support was added in 2019.8, I think. What is your Studio version? :slight_smile:

1 Like

Thanks @loginerror - that’s definitely why :slight_smile:

1 Like

This is awesome. Though it’s being available for quite a long time, today only I knew that this can be done. It’s really helpful in getting dynamic selectors done.

Thank you so much for sharing this tutorial… you are awesome

3 Likes