Selector Not Valid

Hi UiPathers!

My bot ran into an error while going to click a selector. The error message provided is “The selector is not valid”.

When I went to check the value in question it was listed as “Father’s Day Gift Ideas”.

I tried to validate the selector and found the single quote in “Father’s” was the culprit. The string was passed through a variable(string). My question is: How can I adjust my selector to account for scenarios, where a random value within a variable such as this, is encountered with a single quote or any other chars that disrupts the automation?

I’ve attached a screenshot of my selector. Thank you!

image

Hi @alvini,

You can set your selector to replace if below contains. Also you can also test using a wildcard.

Regards,
MY

2 Likes

Hi @alvini

Further to @muhammedyuzuak’s post.

You should clean your string first with escaped characters.

Check out these links:
Library Link #1
Library Link #2

String.Replace Method should assist.

Are you using StudioX?

Cheers

Steve

2 Likes

How can we use this escape ?

Thank you. I am using Modern Design Experience (Studio).

Thank you for these examples, but still not advised as to how to adjust selector to account for these scenarios. Please advise. Thanks

When I use your method, I’m receiving innertext=‘Father's Day’

It’s adding the & within my selector. I have my Variable as

strArticleTitle=“Father’s Day”.Replace(“'”,“'”)
I have also tried.
strArticleTitle=“Father’s Day”.Replace(Chr(39),“'”)

Each time I get same output which is error because it’s looking for ‘Father's Day’ and not ‘Father's Day’

Hey @alvini

To answer your Question: Regex or the other above methods (escaped values / ASCII characters) should work with random/difficult values. Depends on the need really.
So, a fresh approach, lets try Regex in your selector.

I have made a quick Regex pattern which will allow for any single character between the R and S in “Father’s” - take a look and test to see if that suits your needs.

Replace this selector:
image

With this:
innertext=‘Father(.)?s Day Gift Ideas’ matching:innertext=‘regex’

If done correctly, the elements should update with colour changes. Something like the below:
image
Example from Tutorial
image

Tutorial Post:

Hopefully this helps :blush:

Cheers

Steve

My issue is how to apply this to random value in a variable.

Hi @alvini

When this issue fails, can you obtain the selector so it can be logged.

Once we have a pattern we can build a robust Regex Pattern to handle all scenarios.

Hopefully this makes sense.

Cheers

Steve

Ahh. I see. Makes sense. I’ll need to spend more time on Regex. Should I provide the selector?

Hey

Provide whatever you can.

You can learn Regex through my MegaPost.

Cheers

Steve