How to use a regex character and a variable together ?

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
rastek
Posts: 157
Joined: Wed Aug 06, 2014 12:00 pm

How to use a regex character and a variable together ?

Post by rastek » Wed Oct 22, 2014 3:04 pm

I have an variable called user and I want to use it with a regex character ?

Normaly this works for every element that includes the word John
.//ul[#'messaging_list']/?/div/div/?/h3[?'john']

I want to combine this with the variable $user and I dont know how will I do it, please help.

if I wrote sth like ?$user 't does not accept and returns to previous one/

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

Re: How to use a regex character and a variable together ?

Post by odklizec » Wed Oct 22, 2014 8:47 pm

Hi,

It should be possible to use something like this (just an example)...
h3[@InnerText~'?'+$user]
But I'm not quite sure if the same could be done without the attribute name (as in your sample path)? Just try it ;)
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

rastek
Posts: 157
Joined: Wed Aug 06, 2014 12:00 pm

Re: How to use a regex character and a variable together ?

Post by rastek » Thu Oct 30, 2014 2:53 pm

Hi odklizec thanks for the relpy I have one more question

Ranorex gives this regex example for repository and it works fine in repository

/form/button[@text>'sample']


How can I do the same thing in actions ?

for example
I have a Validation action and its Match Value should be start with the variable client

normaly $client works for full name, but I want it to be start client variable

^$client

does not work
Thanks

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

Re: How to use a regex character and a variable together ?

Post by krstcs » Thu Oct 30, 2014 3:29 pm

You cannot directly combine the regex expression with the variable name, you have to do string concatenation.


[@text ~ '^' + $client]


So, if client = 'John Smith', the resulting value would be '^John Smith'.

You could also use the > (starts with) operator for text: [@text>$client].

See this page in the user guide for more information.
Shortcuts usually aren't...

rastek
Posts: 157
Joined: Wed Aug 06, 2014 12:00 pm

Re: How to use a regex character and a variable together ?

Post by rastek » Fri Oct 31, 2014 2:55 pm

Hi krstcs

I am not asking for repository items as I mentioned in the mail

so there is not situation like this -> [@text ~ '^' + $client]

I know the page you wrote but it deals only with repository items in that page

I amsking for Match Value column in the Actions

please check the attachment

Thanks,
Rastek.
Attachments
rastek1.png
rastek1.png (18.72 KiB) Viewed 1433 times

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

Re: How to use a regex character and a variable together ?

Post by krstcs » Fri Oct 31, 2014 3:01 pm

First, you didn't say any of that in either of your other posts, so I didn't know that was the case. When you post, please provide all pertinent information.

Second, you should use Validate.AttributeContains or Validate.AttributeRegex instead of Validate.AttributeEqual. Equal ALWAYS requires character for character match, no regex.
Shortcuts usually aren't...