Repository path if text to search contains quotation mark?

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
mrt
Posts: 257
Joined: Mon Mar 16, 2020 11:31 am

Repository path if text to search contains quotation mark?

Post by mrt » Wed Feb 01, 2023 3:15 pm

Dear all,

how can I get RXPath to explicitely (=) find an element, which text is surrounded by quotation marks?

So I am looking for an element that has text of
'Standard' some other text and special chars like ( or )
The 'Standard' part of the above text breaks everything, even if I put the string above into a variable, the element isnt found when trying to match with =


When I use '<' it works strangely, but is no exact match.
And using '~' is not an option because I would need to escape the full string because of other characters like '(' or ')'.

any ideas?

IvanF
Posts: 151
Joined: Thu Aug 11, 2022 8:55 pm

Re: Repository path if text to search contains quotation mark?

Post by IvanF » Wed Feb 01, 2023 10:47 pm

hi, for the avoidance of doubt, this is for the RxPath field in Spy/repository based on regex - https://www.ranorex.com/help/latest/ran ... ex-syntax/ ?

not for the code using RxPath class - https://www.ranorex.com/Documentation/R ... RxPath.htm?

mrt
Posts: 257
Joined: Mon Mar 16, 2020 11:31 am

Re: Repository path if text to search contains quotation mark?

Post by mrt » Thu Feb 02, 2023 3:09 pm

Ah yes, sorry, I am talking about the RxPath in Spy / Repository, not the RXPath class itself.

IvanF
Posts: 151
Joined: Thu Aug 11, 2022 8:55 pm

Re: Repository path if text to search contains quotation mark?

Post by IvanF » Thu Feb 02, 2023 5:58 pm

Not my strongest area, but, testing on https://regexr.com/, the following syntax seems to find the exact string

(["']Standard["'])(.some.other.text.and.special.chars.like.\(.or.\))

Not sure if that's similar to what you have already tried, don't have a good SUT example at hand with the paths like that to actually verify.

mrt
Posts: 257
Joined: Mon Mar 16, 2020 11:31 am

Re: Repository path if text to search contains quotation mark?

Post by mrt » Fri Feb 03, 2023 8:00 am

Thanks.

For Regex my main issue is that it will also find unwanted matches, when something is following the text I am after, like:
'Standard' some other text and special chars like ( or )
'Standard' some other text and special chars like ( or ) and another text
because as far as I know RegEx is always "contains", not "equal".

Also, these strings are coming from variable, so splitting them apart and building RegExes around them manually is no option.
Of course there is a Regex.Escape which I could use, but then I end up with a "contains" match instead of an "equal"

IvanF
Posts: 151
Joined: Thu Aug 11, 2022 8:55 pm

Re: Repository path if text to search contains quotation mark?

Post by IvanF » Fri Feb 03, 2023 3:15 pm

I see, seems like the contains vs equals part could be addressed with some kind of "end of string" representation added to the regex, for example
Regex1.png
Not yet sure how to sneak it into the variable or append it to it, will take another look a bit later.
You do not have the required permissions to view the files attached to this post.

IvanF
Posts: 151
Joined: Thu Aug 11, 2022 8:55 pm

Re: Repository path if text to search contains quotation mark?

Post by IvanF » Fri Feb 03, 2023 4:24 pm

end-of-line anchor $ seems to be recommended more frequently than /n for "full match" of strings

so, potentially this regex would work

^'Standard'.some.other.text.and.special.chars.like.\(.or.\)$ (removing ^ if it's not the start of the string)

When the whole string comes from the variable, appending ^ and $ at the ends should still work, will maybe require grouping operators. Let me know how your attempts go.

mrt
Posts: 257
Joined: Mon Mar 16, 2020 11:31 am

Re: Repository path if text to search contains quotation mark?

Post by mrt » Mon Feb 06, 2023 7:47 am

'^' and '$' should work, i will try that, thanks

In general I would say, that this behavior (quotation mark inside string do not work) is a bug, because the string is not correctly escaped.