Get value and RegEx

Ranorex Spy, Recorder, and Studio.
wysojak
Posts: 1
Joined: Wed Nov 28, 2018 12:30 pm

Get value and RegEx

Post by wysojak » Wed Nov 28, 2018 2:05 pm

Hi!

I've got a simple, quick question. Here it is.

I have an element in front of me that looks exactly like that:
checkboxes.PNG
checkboxes.PNG (3.56 KiB) Viewed 76 times
and another one that looks exactly like that:
description.PNG
description.PNG (10.65 KiB) Viewed 76 times
What I need to do with them is to get value from the element'slabel from the first screenshot (forget the checkboxes, I don't need those) and check if the first bullet point of the element shown on the second screenshot contains it. The way I want to do this is as follows:

1. Use Get Value action using RegEx (in order to get everything exept spaces, tabs, new lines etc.) and assign it to a variable:
getValue.PNG
getValue.PNG (5.71 KiB) Viewed 76 times
2. Use InnerText Validation action to check.

The problem is as follows:

Get Value action ends gathering the text after first match. Which results in creating a string like '1' or 'Drilling' (one letter or one word). Every time I try different RegEx it either ends up as in case described above, or it ends with something like '↵········1/4·-·5/8·in↵········↵········↵····'. And believe me - I tried every possible angle. Including '/s' and '/S' to avoid whitespaces or even '[^ ]'. Nothing works. There are only two possible reasons for that:

1. I'm doing something wrong or I there is something inside Ranorex I don't know about.

2. Ranorex didn't anticipate a basic testing function which is value comparison.

I know about the RegEx 'toolkit' which is not, infact, a toolkit but a simple RegEx validator. I also know that I could write a simple sanitizer and put it there as a code. But I wanted to use Ranorex itself, as it's advertised. As an all-around comprehensive testing tool.

I will be very obliged for any help, suggestion or - hopefully - an answer. :wink:

User avatar
Support Team
Site Admin
Site Admin
Posts: 11720
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Get value and RegEx

Post by Support Team » Wed Nov 28, 2018 9:42 pm

Hi wysojak,

Are you able to provide multiple Ranorex Snapshot files of these elements with different example values? With these Ranorex Snapshots, I may be able to help you build a regex pattern that only grabs the text required so that you can validate the text exists in the other element.

Looking forward to your reply!

Kind Regards,
Ned
.
Image

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

Re: Get value and RegEx

Post by odklizec » Thu Nov 29, 2018 9:06 am

Hi,

Agree with Ned. It would be very helpful, if you post a Ranorex snapshot for each element. Screenshots are nice, but nowhere as useful as snapshots ;)

At next, if I understand the problem right, there is no need to use regex at all? All you need to do is to get the entire innertext from label of your choice (I guess the checked one?) and simply use the Validate action with AttributeContains parameter. This should be enough to validate, if the text from selected label is available in second screen.
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

User avatar
Support Team
Site Admin
Site Admin
Posts: 11720
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Get value and RegEx

Post by Support Team » Wed Dec 05, 2018 8:59 pm

To anyone else who comes across this thread, the customer sent us the requested Ranorex Snapshot file privately to further investigate. Below is my reply to the customer in hopes it will be useful to you as well.
The problem with this element is that the actual InnerText attribute value contains a lot of leading and trailing whitespace. Below is a screenshot of the value copied and highlighted in Notepad to visually see the whitespace.

1.png
1.png (4.8 KiB) Viewed 29 times
2.png
2.png (3.87 KiB) Viewed 29 times

In order to grab only the data we need (i.e. “5 – 12 in”), we need to use the following RegEx pattern. As you can see in the RegEx tester linked below, this will grab the value between the leading and trailing spaces. This link also provides a nice explanation of how the pattern works. Furthermore, I have also included a screenshot of a sample recording module demonstrating how to use this pattern in Ranorex.

(?:\s*)(.+)(?:\s*)

https://regex101.com/r/IeRMzN/1

3.png
3.png (14.39 KiB) Viewed 29 times
Cheers,
Ned
.
Image