Page 1 of 1

How to use a regex character and a variable together ?

Posted: Wed Oct 22, 2014 3:04 pm
by rastek
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/

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

Posted: Wed Oct 22, 2014 8:47 pm
by odklizec
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 ;)

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

Posted: Thu Oct 30, 2014 2:53 pm
by rastek
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

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

Posted: Thu Oct 30, 2014 3:29 pm
by krstcs
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.

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

Posted: Fri Oct 31, 2014 2:55 pm
by rastek
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.

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

Posted: Fri Oct 31, 2014 3:01 pm
by krstcs
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.