Case Insensitive with equal sign

Ask general questions here.
Mayra
Posts: 68
Joined: Mon Dec 16, 2013 5:27 am

Case Insensitive with equal sign

Post by Mayra » Tue Feb 11, 2014 12:39 am

I have the following xpath:
@innertext~'(?i:'+$datacolumnvalue+')']/../..
it uses a regular expression to do a case insensitive comparison.

Is there a way to use case insensitivity with an equal sign?

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Case Insensitive with equal sign

Post by krstcs » Tue Feb 11, 2014 3:21 pm

No, the equals sign ("=") means both sides of the equation must be exactly the same. In this case, Ranorex will interpret every character in your expression as a literal character when comparing.

The RegEx sign ("~") is the only way to do what you are attempting.

Mayra
Posts: 68
Joined: Mon Dec 16, 2013 5:27 am

Re: Case Insensitive with equal sign

Post by Mayra » Tue Feb 11, 2014 5:28 pm

Hi,
I dont understand. It is not an equation, I have that as part of my path. In some cases is incorrectly identifying strings because it is a RegEx. What I want is to find the exact string regardless of casing. Thanks.
//div[ @innertext~'(?i:'+$datacolumnvalue+')']

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Case Insensitive with equal sign

Post by krstcs » Tue Feb 11, 2014 5:48 pm

It is an expression, a logical equality expression. Ranorex treats the path attributes as expressions at runtime.

As I said, you cannot search for case insensitive strings with the equals ("=") sign, only with the RegEx ("~") sign.

If your current path is finding objects that you don't want it to find, then you will need to make your path more unique.

Without being able to see your application, I can't give you anymore direction than that, unfortunately. If you could post a snapshot of your application under test it would help us see your issue better. http://www.ranorex.com/support/user-gui ... files.html
Shortcuts usually aren't...

Mayra
Posts: 68
Joined: Mon Dec 16, 2013 5:27 am

Re: Case Insensitive with equal sign

Post by Mayra » Tue Feb 11, 2014 8:01 pm

The path is correct, it is not a problem with the uniqueness.
It is matching for example JAP in a string like Japan and I only want it to match exact strings.
Thanks.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Case Insensitive with equal sign

Post by Support Team » Thu Feb 13, 2014 1:57 pm

Hi Mayra,

I am not sure I got your question, but if you just want that the exact string matches you need to use the normal "=", like: @innertext='Japan'.

Regards,
Markus

mrollins
Posts: 10
Joined: Wed Aug 28, 2013 6:35 pm

Re: Case Insensitive with equal sign

Post by mrollins » Tue Feb 25, 2014 6:29 pm

Mayra wrote:The path is correct, it is not a problem with the uniqueness.
It is matching for example JAP in a string like Japan and I only want it to match exact strings.
Thanks.
If you want to match only exact strings in an insensitive manner you should use the ^ and $ delimiters for start and end of line respectively.

So your regex would become:
//div[ @innertext~'^(?i:'+$datacolumnvalue+')$']
Michael Rollins

Mayra
Posts: 68
Joined: Mon Dec 16, 2013 5:27 am

Re: Case Insensitive with equal sign

Post by Mayra » Fri Apr 11, 2014 7:09 pm

Thanks Michael, looks like that is what I need

Mayra
Posts: 68
Joined: Mon Dec 16, 2013 5:27 am

Re: Case Insensitive with equal sign

Post by Mayra » Mon May 12, 2014 10:44 pm

I have one case where the regular expression is not working. I got it down to be the '(' within the string that I am using in the value to be found, example:
tag[@innertext~'^(?i:'+$graphnodelabel+')$']
if graphnodelabel contains a ( then the value is not found, example not found:
tag[@innertext~'^(?i:'+'smtp (TCP:25)'+')$']

Is there a way to use ( within the string to be found in the regular expression?
Thanks.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Case Insensitive with equal sign

Post by odklizec » Tue May 13, 2014 7:03 am

The problem is, that the parentheses are reserved characters in regex, which must be escaped. I think the easiest way around would be to add \ in front of each parentheses in your test data, from which you fill that $graphnodelabel variable?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Case Insensitive with equal sign

Post by krstcs » Tue May 13, 2014 3:07 pm

odklizec is correct, you need to escape the parenthesis in your data. I've had the same issue with phone numbers in my data set (US phone numbers have "(XXX) XXX-XXXX" format).

I use SQL Server for my data, so in my queries I just have an extra column called "Escaped_PhoneNumber" that I populate by replacing each "(" with "\(" and each ")" with "\)" so that I now have the regular phone number for validation comparisons, and the escaped one for XPath regex expressions.

If you are using Excel, you can add another column that is an expression from the raw column that does the same thing I did above.

If you are using CSV or simple data connectors, you will need to do it manually for each row. (This is one reason I recommend at least Excel, but really a true database is best and SQL Server Express is free and integrates directly with Ranorex.)
Shortcuts usually aren't...