I am testing an application that contains a number of buttons. Some of those buttons contain a text element with an index of 4 and a text value of
"(Voided)". Using an XPath that ends with "/button[@automationid='button']/text[index()=4 and @text='(Voided)']" finds the buttons that contain a text element with an index of 4 and a text value of "(Voided)".
How can that XPath be changed to find the first button which does not contain a text element with an index of 4 and a text value of
"(Voided)"?
Thanks.
Using XPath to identify an element not containing something?
Re: Using XPath to identify an element not containing something?
Hi,
Well, the obvious solution looks like this:
But I guess you mean to find a button, which actualy does not contain the Text sub-element? In this case,
I'm afraid, there is no xpath way to detect this. I've already discussed a similar issue with Ranorex folks and there is no xpath way to detect a non-existence of an element. I think the only solution is using Find method?
Well, the obvious solution looks like this:
Code: Select all
/button[@automationid='button']/text[index()!=4 and @text!='(Voided)']
I'm afraid, there is no xpath way to detect this. I've already discussed a similar issue with Ranorex folks and there is no xpath way to detect a non-existence of an element. I think the only solution is using Find method?
Last edited by odklizec on Thu Jan 18, 2018 1:13 pm, edited 1 time in total.
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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
-
- Certified Professional
- Posts: 344
- Joined: Tue Feb 18, 2014 2:14 pm
- Location: Co Louth, Ireland
- Contact:
Re: Using XPath to identify an element not containing something?
Thanks for your helpful reply odklizec.
Yes, that's exactly what I want to do.odklizec wrote:...I guess you mean to find a button, which actual does not contain the Text sub-element?..
Thanks, are you referring to writing some code to identify the element?odklizec wrote:...I think the only solution is using Find method?
Re: Using XPath to identify an element not containing something?
Yes, you will have to write some code to identify a button without requested sub-elements.Fergal wrote:Thanks for your helpful reply odklizec.Thanks, are you referring to writing some code to identify the element?odklizec wrote:...I think the only solution is using Find method?
Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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
-
- Certified Professional
- Posts: 344
- Joined: Tue Feb 18, 2014 2:14 pm
- Location: Co Louth, Ireland
- Contact:
Re: Using XPath to identify an element not containing something?
Thanks again odklizec for steering me in the right direction. Clarifying that helped me to stop focusing on that approach and figure out a way that works.odklizec wrote:there is no xpath way to detect a non-existence of an element
I've discovered that "Voided" text element exists in all of the buttons, but is invisible in the button required. The updated XPath, which works by finding the parent element (i.e. the required button) of the first invisible text element, ends with the following:
Code: Select all
...text[@name=' (Voided)' and @visible='False'][1]/..
Re: Using XPath to identify an element not containing something?
Of course, if the child element is available, just not visible, your solution should be just fine. In my case, sub-elements are sometimes not available at all 

Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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