How to use a variable in: <webctrl aaname=VARIABLE />

Is it possible to use a variable in a webctrl statement? If so, how do I declare it and use it in the Selector Editor?

I have the following statement that works fine:

I want to turn it into

so I can assign whatever VARIABLE (Chapter 1, Chapter 2, etc) I need, and have the VARIABLE populate the webcrtl statement with the selected chapter.

Thanks!

Fritz

2 Likes

hi @Hibb

You can use variables inside that but be careful for string termination and opening and append variable where you wants with “+” operation

for eg.

"<webctrl aaname='Chapter " + counter_variable+ "' parentid='Week2_control' tag='A' />"

Let me know if you have doubts on this.

Regards…!!
Aksh

1 Like

"<webctrl aaname='Chapter " + variable_name + "' parentid='Week2_control' tag='A' />"

increment variable_name as required

Hello,

Here’s an example of passing variables to selectors.

Hope It helps!

Regards,

Hi Aksh,

Thanks for the response, but I can’t seem to get the syntax correct.

This one works:

.
.
.

When I use WEEKNUMBER it doesn’t work

.
.
.

.
.
.

I get this error:

.
.
.
Any additional help or insight yu have would be very appreciated.

Fritz

Use the assign activity to set the selector text in a string variable and use that variable instead. Assign the WeekNumber variable before assigning the selector text variable.

Hi @Hibb ,

The ideal and the efficient way of using a dynamic variable in selector can be achieved by using String.format

You can save selector in a string variable :

varSelector =  "<webctrl aaname='Chapter {0}' parentid='Week2_control' tag='A'>"
varChapterName = "1"

You can then use String.format(varSelector,varChapterName) in Edit Selector window.

You can read more about this function VB.NET String.Format Examples: String and Integer - Dot Net Perls

Hope this helps.

Regards,
V

9 Likes

hi @Hibb

with the same post of me just replace counter variable to counter_variable.tostring and let me know, it works well.

or for debugging purpose you are getting the same string properly use write line activity to display your selected string.

and a quick note please remove this &quot to " in properties windows well. uipath sometimes when you uses this with popup modification it shows like this and because of selector interpret it and shows error so without make properties selector option pop up larger make changes above and use it.
best to cross check string write line it.

regards…!!

Hi Everyone,

I want to thank everyone for all their advice and help. I really appreciate your generosity with your time and knowledge. Unfortunately, I still haven’t resolved my problem. I’m trying to put a variable in the Selector Editor.

I want to chose one of the following hyperlink sections on a web page using a variable:

I want to select one of the sections based on the value of a variable called, varSectionName, which is declared as a string and initialized with a value equal to: Strategic Management Ch., Week 3 Electronic Readings, etc.

The default sequence works correctly and clicks on “Week 3 Electronic Readings”:
.
.


.
.

.
.
However, I want to replace the first Edit Attribute “Week 3 Electronic Readings” with the variable varSectionName

Aksh, Vinay and others suggested:

“< webctrl aaname='” + varSectionName+ “’ parentid=‘Week3_control’ tag=‘A’ / >”

I tried to follow their suggestions, but it doesn’t like the outer quotes and I get an error.
.
.

.
.
When I don’t use the outer quotes and I put varSectionName in the Section Editor I get the following syntax:
.
.

.
.
The double quotes are replaced by the HTML code for double quotes.

Because it doesn’t recognize varSectionName as a variable, it’s putting “+varSectionName+” into aaname as the string "+varSectionName+" and then it’s trying to locate "+varSectionName+" in the webpage.

How do I get a variable into the Selector Editor so that: and it recognizes varSectionName as “Week 3 Electronic Readings” and searches for webctrl aaname=‘Week 3 Electronic Readings’

========
PS…

I like Vikas’s suggestion of:
varSelector = “”
varChapterName = “Week 3 Electronic Reserve Readings”
Using String.format(varSelector,varChapterName) in Edit Selector window.

But I don’t know how to put it in the Selector Editor either.

Thanks again for everyone’s help…

I finally figured out how to use a variable in a selector.

I was trying to edit a selector using the Selector Editor, but it didn’t work. Instead of using the Selector Editor I used the Expression Editor and it worked perfectly.

Thanks for all of your help!

3 Likes

hi @Hibb

i have mentioned this already termed as editor as pop up and already said that html conversion like &quotes prob.

it is good now you knows and solved your prob.

a quick note please remove this &quot to " in properties windows well. UiPath sometimes when you uses this with popup modification it shows like this and because of selector interpret it and shows error so without make properties selector option pop up larger make changes above and use it.

Regards…!!

Hey Akshay,

I know you said that about the editor pop up, but I’m new to UiPath and didn’t know how to get the Expression Editor to pop up. Once I was able to replace the Selector Editor with the Expression Editor everything you said to do worked and my problem was solved.

Thanks again,

Fritz

Hello @Hibb,

Kindly use the method as per the attached sample xaml file.

Test.xaml (6.2 KB)

Hope that helps,

Regards
Madhura

3 Likes

Hi,

I am using UiPath to populate a web form which includes consecutive drop down boxes. Each time the page loads, the ID of the drop down box element changes. For example for the 1st, 2nd and 3rd page loads, the element tag references are:

1488011548900
1488012126331
1488012507658

To address this I have inserted a wildcard as follows: 148801*

The problem I have is that for the second drop down box, I face the same problem with dynamic references for each page load:

1488011551848
1488012129231
1488012510388

If I, again, use the wildcard 148801*, for the second drop down box, when the UiPath script, it operates twice on the first drop down box rather than consecutively operating on the 1st and second drop down boxes.

Please advise how to fix this.

Thanks

Tobor

  • build a better selector by including other attributes in the selector
    or
  • identify the dropboxes using fixed relative elements (anchor)

Edit the selector in as a string instead of opening the selector builder if you want to add a variable to to a selector.

Please note that doing this makes UIPath recognize the value as a string instead of a selector, so you won’t be able to edit it as a selector after adding a variable.

Before:

"<html title='staticvalue'/>"

After:

"<html title='" + dynamicValue + "'/>"
5 Likes

@Hibb

How did you manage to use the Expression Editor. I have the same problem that you had but I am not able to find any Expression Editor, only the Selector editor

Hi Morten,

The advice I got from the group on using variables in the Expression Editor was excellent, but like you I struggled to get the Expression Editor instead of the Selector Editor. As you found out, variables don’t work in the Selector Editor. Instead of using record or data scraping to define the object you want to manipulate with the Expression Editor you have to manually drag the object from the list on the left. Then when you go into its properties the Selector will bring up the Expression Editor instead of the Selector Editor. What I now do is use “record” to stage my process, then delete the object on which I want to use the Expression Editor and then manually added it back. And like magic, I am the able to manipulate it with the Expression Editor when I click on the Selector.

I hope this helps. If not let me know and I’ll try to re-explain what I do to get the Expression Editor.

Hibb

4 Likes

Using the Expression Editor worked for me as well. Thanks!

1 Like

I am also new to UiPath and the expression editor works for me too, Thanks!..however would like to know how can the regular selector be edited to include variables using uiexplorer or any other means. Although the expression editor works great for me when there is only a click activity however when i try expression editor in scenarios where both click and followed by type activity is required, expression editor doesn’t work well. Also, the selector has content in multiple lines, would like to know if expression editor has limitations around.