Variable Selectors with & not working and returning Exception Type: invalidCastException

Hi,

I have created an array of Report names, and am creating a “for each” loop to interact with each of the reports which are in an online application (step 1 being to double click to report to open). Using a log message I have confirmed that the array item is being read correctly in the first instance and this matches the name of the first report shown on screen. So I am trying to create a selector using each of the Report names as a dynamic variable:

" webctrl parentid=‘xyz’ aaname=’"+strReportName.ToString()+"’ /" (in both quotes and triangle brackets, but brackets don’t show? Also xyz changed, but works elsewhere, don’t think that’s the issue)

strReportName is a string type variable already, but I tried with/without .ToString in case. However when I run the component it is unable to find the selector:

Message: Unable to cast object of type ‘Newtonsoft.Json.Linq.JValue’ to type ‘System.String’.

Exception Type: InvalidCastException

I have created this in expression editor as well, as per other suggestions I have seen which others say fixed their issues.

Any help would be greatly appreciated. Many thanks!

1 Like

quick tip is to use the backslash “\” infront of the character that won’t show up in your post.
Like this: < and \>
also, you can use the code syntax like with ``` surrounding your text and you don’t need to use the backslash. Like this:

< \>

Can you verify the selector before it uses it in either a Message box or Write Line —paste entire selector. This will atleast tell you that the variable and selector is correct.

Regards.

Hi Clayton,

Thanks for your quick response, and apologies for this obvious question - how do I print out the selector? I tried however it says it can’t convert ‘System.Xml.Linq.XElement’ to ‘String’, and when I convert to string it just prints out the selector as is, without using the variable? This is same for both write line and log message.

Cheers

Generally an issue with the selector.

Can you please put a screenshot of your whole selector?

Also ToString dosent require a (), remove that and try.

Thanks Nadim,

I originally tried without the () with the same result, and saw someone suggest them so figured it was worth trying.

image

This is within an attach browser sequence, all steps before this work and have very similar selectors.

Thanks

Your selector looks good. Is it still not running?

Cant be sure if it can cause an issue, but can you remove the spaces before/after +

Still not working, it comes up with the following (even after removing the spaces):

As you can see, in the bottom right it says the selector isn’t valid, so perhaps it can’t find the selected element on the page, could that be the issue, or is it that the selector itself can’t be read properly?

Is it possible for you to share the xaml for this seq? I would like to have a look so i can identify the issue.

No, in that case you would get element not found for that selector.

I am too new to upload attachments, sorry, I tried. Maybe new accounts take a few days to verify properly as I have also completed orchestrator and foundation training and no badges are appearing, so perhaps my account is still limited.

The reports I’m trying to click are behind a “frame” within IE, so selectors have been tricky for this whole process, however as mentioned, worked for others (as an example \ <webctrl parentid=‘com.hyperion.bpmex.web.tree.GridView-*’ aaname=‘Report_Books’ /> worked fine for me to get to the reports).

I’m attaching a sample message box seq, copy the selector from there and see.
selector.xaml (4.8 KB)

Thanks for your help!

I copied your text into notepad, updated the xyz, then copy and pasted into the selector input on the properties panel, before attempting again to run. Exactly the same error message though?

Like i added the message box , can you use the same in your seq, paste your selector and see if the output is printed in pop-up is as expected?

image

Which is what I believe the selector should say, thanks! Still errors directly after, but selector seems to work

Does your aaname have any other special char other than &?

It has & and -, otherwise all alphanumeric

Hi. I just meant to copy the string from the Expression Editor and paste it into a Message Box or Write Line. This will show what the selector really looks like with your variable. If there is a weird character or something getting in there, then your selector will fail.

Also, yeah, any special characters like “&” will need to be replaced with a wildcard “*”.

1 Like

I tried and ‘&’ is what is breaking your selector. Its not able to escape it and take the value as a string as its a concatenation operation in VB.

If i can suggest, can you replace & in you variable with * and then try it?

use something like this: Assign newVar to strReportName.Replace("&","*") then use that var in your selector variable

1 Like

You guys are both heroes, can’t believe I didn’t think of that, so simple!!

My config file (where report list is stored) now looks like MASH* with all the * but whatever works right?

Thanks again!

1 Like