How to express not contains in xpath

Ask general questions here.
martinsw
Posts: 72
Joined: Fri Dec 09, 2011 2:48 pm

How to express not contains in xpath

Post by martinsw » Mon May 21, 2012 12:46 pm

Hi,

I want to ensure that the value of an adapter in the xpath does not contain a particular word. Can you please advise how I do this? I had a look at the page below but couldn't see an explanation for what it is that I am trying to do

http://www.ranorex.com/support/user-gui ... xpath.html

'!=' means 'not equal' and '~' means 'contains' so I thought combining the two would give me the desired result i.e. '!~' but it turns out that this doesn't seem to be valid syntax.

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: How to express not contains in xpath

Post by Support Team » Tue May 22, 2012 9:12 am

Hi,
Can you please advise how I do this?
So the thing is that you want to ensure that a particular word is not in a specific attribute of a specific element?
In general the RxPath and the attribute should be used to uniquely find the element, in your case you will find "all" elements which don't contain the word and I think you will find many elements.

I would suggest checking the string with one of the normal C# methods in UserCode or with a Validation action (AttrubuteNotContains).

Regards,
Markus
Ranorex Support Team

martinsw
Posts: 72
Joined: Fri Dec 09, 2011 2:48 pm

Re: How to express not contains in xpath

Post by martinsw » Tue May 22, 2012 3:12 pm

Hi Markus,

Sorry I didn't explain very well. What I want to ensure is that the value of an attribute in the xpath does not contain a particular word.

For example, if I want to find all buttons where the text attribute contains the word 'Add', I would express it like this:

/button[@text~'Add']

So what if I want to find all buttons where the text attribute does not contain the word 'Add'. How would I express this in the path? /button[@text!~'Add'] does not work.

When validating within my recording, I am trying to stick to only using 'validate exists' where possible. So this means that the not contains expression must be expressed in the xpath itself. If there is no way of doing this within the path then I will use the validate not contains action in the recording. But i just wanted to check first.

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: How to express not contains in xpath

Post by Support Team » Wed May 23, 2012 9:10 am

Hi,
Support Team wrote:So what if I want to find all buttons where the text attribute does not contain the word 'Add'. How would I express this in the path? /button[@text!~'Add'] does not work.
The "!~" will be supported within one of our future releases.
You can overcome your issue using follwoing regular expression within your attribute equation in your RanoreXPath:

Code: Select all

/button[@text~'^((?!Add).)*$']
Regards,
Tobias
Ranorex Team

martinsw
Posts: 72
Joined: Fri Dec 09, 2011 2:48 pm

Re: How to express not contains in xpath

Post by martinsw » Thu May 24, 2012 9:18 am

ok thanks