Question re recognizing text zero or more times in XPath

Ask general questions here.
Fergal
Certified Professional
Certified Professional
Posts: 298
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Question re recognizing text zero or more times in XPath

Post by Fergal » Fri Mar 13, 2015 12:11 pm

[Ranorex 5.2.2, running on Windows 7]

From the user guide "the character to the left of the asterisk in the expression should match zero or more times". I have an XPath that includes the following;
text[@name~'9/1*3*/2016']
The objective of this XPath was that the item would be identified, regardless of the day value in that date. E.g. the following values would be recognized; '9/27/2016, '9/12/2016' and '9/7/2016'. However, the only item that XPath value is identifying is '9/13/2016'. It will NOT identify '9/12/2016'.

What does the XPath need to look like, so that it can identify any day value in the date?

Thanks!

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

Re: Question re recognizing text zero or more times in XPath

Post by odklizec » Fri Mar 13, 2015 12:51 pm

Hi,

Try this expression:

Code: Select all

(9\/\d*\/2016)
It's definitely not correct "date" validation expression, because it will match "any" day number, including non-existing day numbers, like 32 or 320 ;)

I think the valid "day" regex should look like this (matches anything between 01-31 or 1-31)

Code: Select all

(0[1-9]|[1-9]|[12][0-9]|3[01])
So your expression should look like this:

Code: Select all

(9\/(0[1-9]|[1-9]|[12][0-9]|3[01])\/2016)
BTW, I would suggest you to try the expressions (before using them) in a regex editor/tester, like this one:
https://regex101.com/

Hope this helps?
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

Fergal
Certified Professional
Certified Professional
Posts: 298
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Re: Question re recognizing text zero or more times in XPath

Post by Fergal » Mon Mar 16, 2015 2:20 pm

Thanks for all of that odklizec, it works great and is just what I needed!

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

Re: Question re recognizing text zero or more times in XPath

Post by krstcs » Mon Mar 16, 2015 2:20 pm

Note that Ranorex is built on .NET, so it uses .NET's Regex evaluation engine. Most web-based regex testers only use the JavaScript regex engine, so there will be differences.

The tool I have found most useful for .NET regex is Expresso. It is a windows application, but it is lightweight and powerful.
Shortcuts usually aren't...

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

Re: Question re recognizing text zero or more times in XPath

Post by odklizec » Wed Mar 18, 2015 9:25 am

Hi krstcs ,

You are right. This online one seems support also .NET regex engine and even offers code samples in various languages...
https://www.myregextester.com/index.php
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