Generating IDs Dynamically

Hi
I would like to generate the ID property of Select element. My requirement is to feel the Hrs. field for 5 days, each field has ID as HH_1, HH_2 … HH_5. So I am trying to use a for loop which will iterate 5 times and generate the HH_, for this I have defined one String variable HH_id and Assign the following value to it in a loop
String.Format("<html app='firefox.exe' title='Login'/> <webctrl id='ddlIN_HH_{0} tag='SELECT' />",count.ToString)
Using this variable in Selector Expression Editor. But getting below error.

RemoteException wrapping UiPath.Core.InvalidSelectorException: The selector is not valid  ---> RemoteException wrapping System.Xml.XmlException: 'SELECT' is an unexpected token. Expecting white space. Line 1,
position 95. 
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.Throw(String res,
String arg)
   at System.Xml.XmlTextReaderImpl.ThrowExpectingWhitespace(Int32 pos)
   at System.Xml.XmlTextReaderImpl.ParseAttributes()
   at System.Xml.XmlTextReaderImpl.ParseElement()
   at System.Xml.XmlTextReaderImpl.ParseElementContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)
   at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
   at System.Xml.XmlLoader.Load(XmlDocument doc,
XmlReader reader,
Boolean preserveWhitespace)
   at System.Xml.XmlDocument.Load(XmlReader reader)
   at System.Xml.XmlDocument.LoadXml(String xml)
   at UiPath.Core.Selector.FromXmlString(String xml)
   at UiPath.Core.Selector..ctor(String theSelector)
	--- End of inner exception stack trace ---
   at System.Activities.Statements.Throw.Execute(CodeActivityContext context)
   at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance,
ActivityExecutor executor,
BookmarkManager bookmarkManager)
   at System.Activities.ActivityInstance.Execute(ActivityExecutor executor,
BookmarkManager bookmarkManager)
   at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor,
BookmarkManager bookmarkManager,
Location resultLocation)

I have no clue where is the error. It would be great if someone help me. Thanks

1 Like

Hi @AbhayGodbole

There is a feature in Studio that allows you to use variables in your selectors, please see here:

1 Like

Hi
I am getting validation error:

I am defining the variable as follows as per your explanation…

In my case I would like to change the value HH_Counter. The original selector is
<webctrl id='ddlIN_HH_1' tag='SELECT'/>

Please suggest

2 Likes

For the selector to validate, you need to provide it with a default value. In your case, add the value “ddlIN_HH_1” as the default value of your variable HH_id and it will work.

2 Likes

@AbhayGodbole Try below selectors and let me know

id=ddlIN_HH_{{id}}

1 Like

Yes, I have given the same default value below is the screenshot


Still its not validating…

Hi Indra,

Tried as per your suggestion, but no luck

Hi Indra,
This worked… it surprised me, as at design time though its not Validating, but at run time its working exactly the way I wanted. in the for loop I have incremented the id variable. One observation I had. when I drag the Select Item/Type In activity and locate the control with Indicate on Screen, and go to edit selector, its showing validation error, then when used Repair Validate is green but there is no change in the selector, very weird behavior… any thoughts ?

Hi
This worked with ddlIN_HH_{{id}}. it surprised me, as at design time though its not Validating, but at run time its working exactly the way I wanted. in the for loop I have incremented the id variable. One observation I have. when I drag the Select Item/Type In activity and locate the control with Indicate on Screen, and go to edit selector, its showing validation error, then when used Repair Validate is green but there is no change in the selector, very weird behavior… any thoughts ?

1 Like

Interesting. I think it might have something to do with the type of activity you are using - mainly the Select activity. Or actually, the type of the element you are automating - the selection box.

It seems to me that the Select activity cannot find the selector when not in runtime due to the selector being ‘hidden’ at the time of validating (the selection box being closed). Repairing it might force Studio to dig deeper into the selection box and finding the element it should, similar to what would happen on runtime.

I think there is some space for improvement here (it should validate selectors for selection boxes, even if the selection boz is not open to display the options).

I’ll check with the team to see if I’m correct here in my assumptions and whether we can improve this behaviour.

2 Likes

I have just checked now, in the new project with different site as well as my timesheet entry site, its working fine. But when I am trying in my old project by deleting the activity and recreating its behaving weird, looks like its not a issue as such, but something strange behavior with particular workflow/project… not sure :slight_smile:

3 Likes

Could it be that the older project had older dependencies installed than the new one? Especially the UiPath.UiAutomation.Activities package.

Actually this is not a old project, this is created with latest UiPath version, but still I have updated the package with more latest version, but still its not getting validated. Its really strange behavior.

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