Dictionary in Selectors

Hi,

I have a query can we pass dictionary type variable in selector?

Dictionary name = Details( type of string, string )

Like aaname = ‘Details.Key’

@Harbansh_Singh
yes , you can pass dictionary type variable
like this
"<webctrl aria-role=‘button’ css-selector=‘body>div>div>form>div>div>div>center>input’ tag=‘INPUT’ type=‘submit’ aaname=‘“+splitRes(“Selector”)+”’ />"

Thanks @sandeep13 for your reply…

What if we have dynamic dictionary where we are passing key dynamically…

Like in the given example it is like : splitRes(“selector”)
Where we have to pass key name hard-coded, how we can make it dynamic where key value we can pass differently

Like splitRes.Key

Just use a variable in place of “selector”

KeyName = “test”
splitRes(KeyName)

…will return the same as splitRes(“test”)

@sandeep13 I tried the above example it is not wokring for me…
Below is the screenshot

@postwick thanks
Yes, this could be one option which I also thought of…
But is there is any way to use the dictionary dynamically directly without assigning it to another variable and then use it

"<webctrl aria-role='button' css-selector='body>div>div>form>div>div>div>center>input' tag='INPUT' type='submit' aaname='" + splitRes("Selector")+ "' />"

I think that’s correct. It’s all about getting the single and double quotes correct so splitRes is not inside double quotes. Also, don’t copy/paste right from here, the type of quotes you get won’t be correct. Copy and paste into notepad, fix up the quotes, then copy paste into Studio.

Also, it’s good to avoid css-selector because it’s unreliable.

I cross checked the syntax it seems the same.

In the output window it is converting the double quotes(") to &quot. And in the selector it is searching aaname with that value., Is it a problem here

The syntax isn’t the same. Looking at your screenshot you have agrtest(“Name”) inside the double quotes so it’s used as a literal inside the aaname, instead of being replaced by the value.

Below is the syntax I am using

After saving the selector editor the double quotes converter into &quote;

Hi @Harbansh_Singh,

Step 1 : Assign : aanameValue = DicExample("Name").ToString (.ToString is not needed but if you have an object type later this would be a safe approach)
You can also avoid the Step 1 is you use the right click method in Step 2. It would just mean that you have to assign a value to your aanameValue variable later.

Step 2 : Now go to your selector and right click after the aaname and use your aanameValue variable. This way you avoid the issues with combining single and double quotes. The interpreter knows that you want your aanameValue variable in the place of

aaname='{{aanameValue}}'

Read this documentation and see the GIF in this page : Dynamic Selectors

You can’t do it in there. You have to go to the Properties pane, copy the entire selector, paste into Notepad, edit in Notepad to get it how you want it, then copy/paste back into the Properties pane. You can’t do it in the selector window you’re using, because it doesn’t show the begin and end double quotes.

This is unnecessary extra work and extra variables to manage, and makes everything harder to interpret in the future should troubleshooting or changes need to be made.

Hi @postwick,

I disagree for two reasons:

  1. To me troubleshooting a syntax error ( no quotes? single quotes? double quotes?) while there is a proven method which is already standard function in Studio is hassle as well.

Agreed that to know what occurs in the background may be is one of the motivations to try and pass the dictionary key value directly in the selector.

  1. The approach mentioned is the UiPath best practice/recommended approach to handle dynamic selectors. Why hard code dictionary keys when you can parametrise it using variables or arguments?

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