Variable in selector not working

I have created a web app automation project which contains many ‘click’ and ‘type into’ activities. and almost every activity’s selector contains title attribute. which may vary while moving that project into production environment. so i planned to set a string variable instead of static title value and implemented that as follows.

< h t m l t i t l e= ‘"+varName+"’ / >
(without the spaces in html title)

but its not working. Anyone please help me to solve this problem.

(fyi , you can use “\” infront and it will show the < without the spaces) :stuck_out_tongue:

Please output the entire string in Message Box or Write Line to verify the selector is correct and matches what it would say with UiExplorer etc.

Then, you can use that string in the selector text box in properties.
Should be like this:
"<html title=’"+varName+"’ />"
including the outer quotations.

Regards.

2 Likes

Thanks Clayton. I will try and let you know if its working or not.:smiley:

@shankm
After modifying the selector, use it by dragging a new activity and paste the selector in selector region of properties.
Don’t indicate the element on screen.

Regards,
Mahesh

@ClaytonM How do we handle if the variable varName has special characters like ( ’ , " )

I would probably use a Regex pattern, like this one "[^\w\d]+"
Then, you can use .Match or .Replace
Regex.Match(str, pattern).Success
or
Regex.Replace(str, pattern, "")

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

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.