xpath using or for two different paths

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
David Zita
Posts: 27
Joined: Thu Mar 31, 2016 12:20 pm

xpath using or for two different paths

Post by David Zita » Tue Feb 25, 2020 12:36 pm

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.

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

Re: xpath using or for two different paths

Post by odklizec » Tue Feb 25, 2020 12:47 pm

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:

Code: Select all

//div/div?/button/span?
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

David Zita
Posts: 27
Joined: Thu Mar 31, 2016 12:20 pm

Re: xpath using or for two different paths

Post by David Zita » Tue Feb 25, 2020 1:07 pm

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?

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

Re: xpath using or for two different paths

Post by odklizec » Tue Feb 25, 2020 1:10 pm

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 ;)
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

David Zita
Posts: 27
Joined: Thu Mar 31, 2016 12:20 pm

Re: xpath using or for two different paths

Post by David Zita » Tue Feb 25, 2020 2:48 pm

So, I have a general structure of a panel that consist of

Code: Select all

div[@class='panel panel-default']
with 2 children

Code: Select all

div[@class~'panel-heading'] 
div[@class='panel-body']
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? :?:
You do not have the required permissions to view the files attached to this post.

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

Re: xpath using or for two different paths

Post by odklizec » Tue Feb 25, 2020 3:00 pm

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...

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 Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

David Zita
Posts: 27
Joined: Thu Mar 31, 2016 12:20 pm

Re: xpath using or for two different paths

Post by David Zita » Wed Feb 26, 2020 7:12 am

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*

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

Re: xpath using or for two different paths

Post by odklizec » Wed Feb 26, 2020 7:37 am

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 ;)
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

User avatar
Stub
Posts: 341
Joined: Fri Jul 15, 2016 12:35 pm

Re: xpath using or for two different paths

Post by Stub » Wed Feb 26, 2020 8:42 am

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.