Is it possible to use some OR operator to have one Repository item with two possible xpaths? something like this:
\div\div\button or \div\button\span
According to this post https://stackoverflow.com/questions/125 ... r-in-xpath xpath in general should be capable of this, but the questions is, is it Ranorex? Thanks.
xpath using or for two different paths
Re: xpath using or for two different paths
Hi,
Ranorex implementation of xpath currently supports Conditions only for attributes (e.g. .//text[@platformclass~'.LabelRenderer$' and @text~'REFERENCE:']). But you should still be able to create an advanced xpath, pointing to multiple targets. For example, your problem could be solved by xpath like this:
Ranorex implementation of xpath currently supports Conditions only for attributes (e.g. .//text[@platformclass~'.LabelRenderer$' and @text~'REFERENCE:']). But you should still be able to create an advanced xpath, pointing to multiple targets. For example, your problem could be solved by xpath like this:
Code: Select all
//div/div?/button/span?
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
-
- Posts: 30
- Joined: Thu Mar 31, 2016 1:20 pm
Re: xpath using or for two different paths
Ok, my actual problem is these two paths that I need to point to the same element:
1) div[@class~'panel-heading']/strong[@innertext='Available Actions']/parent::div/parent::div
2) div[#'actionpanel']
Is it possible using advanced xpath? I haven't figured it out. The problem is in the links to parents that are not able to be optional, am I correct?
1) div[@class~'panel-heading']/strong[@innertext='Available Actions']/parent::div/parent::div
2) div[#'actionpanel']
Is it possible using advanced xpath? I haven't figured it out. The problem is in the links to parents that are not able to be optional, am I correct?
Re: xpath using or for two different paths
Hi,
Could you please post a Ranorex snapshot of the problematic element? It's always best to construct xpath on real UI or at very least snapshot
Could you please post a Ranorex snapshot of the problematic element? It's always best to construct xpath on real UI or at very least snapshot

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
-
- Posts: 30
- Joined: Thu Mar 31, 2016 1:20 pm
Re: xpath using or for two different paths
So, I have a general structure of a panel that consist of
with 2 children
There could be several different panels so to distinguish I look inside the heading for a label (in <strong> tag). Then I navigate 2 times up to get to the main entry point panel-default. From there I can navigate to the body part. This is the normal case and such structure works for all the panels. Even for the "Available actions" panel shown in the defaultPanel.rxsnp. But sometimes this panel has 2 tabs and its inner structure is completely different. The heading part is deeper (there is an UL with LIs for each tab) and the body part is inside a div which actually is uniquely identified by ID. So in such case I can skip the get-text-from-heading-and-move-two-times-up thing and go for the body righ a way. But unfortunatelly I am not able to write it in a single rxpath entry. Or am I? 
Code: Select all
div[@class='panel panel-default']
Code: Select all
div[@class~'panel-heading']
div[@class='panel-body']

You do not have the required permissions to view the files attached to this post.
Re: xpath using or for two different paths
Hi,
So if I understand it right, you simply want to find element strong[@innertext='Available Actions'] and from there you want to get back to div[@class='panel panel-default']? In this case, this xpath should work with both snapshots...
So if I understand it right, you simply want to find element strong[@innertext='Available Actions'] and from there you want to get back to div[@class='panel panel-default']? In this case, this xpath should work with both snapshots...
Code: Select all
//div[@class~'panel-heading']//strong[@innertext='Available Actions']/ancestor::div[@class='panel panel-default']
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
-
- Posts: 30
- Joined: Thu Mar 31, 2016 1:20 pm
Re: xpath using or for two different paths
Thanks, that will do that
I didn't know about the 'ancestor' keyword, that will help me in other situations as well. And I also found out it's possible to write something like this:
/div?[@id="actionpanel"]
to look for optional specific div. So thanks again, problem solved *MISSING_THUMBSUP_SMILIE*

/div?[@id="actionpanel"]
to look for optional specific div. So thanks again, problem solved *MISSING_THUMBSUP_SMILIE*
Re: xpath using or for two different paths
Hi,
I'm glad I could help
BTW, another small 'better usability' tip. If you want to see a list of available relationship operators (xpath elements or attributes), do the following. While typing in Ranorex Spy xpath input, press Ctrl+Space shortcut. This will show you a list of available xpath command. Using this shortcut after '/' character, will display list of relationship operators
I'm glad I could help

BTW, another small 'better usability' tip. If you want to see a list of available relationship operators (xpath elements or attributes), do the following. While typing in Ranorex Spy xpath input, press Ctrl+Space shortcut. This will show you a list of available xpath command. Using this shortcut after '/' character, will display list of relationship operators

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
Re: xpath using or for two different paths
Ooo, nice tip, I didn't know about ancestor either, though I have used predecessor and successor a lot. I have added that one to my notes.