XPath code for "Most Recent Ancestor", and other keywords

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
ancleg
Posts: 12
Joined: Thu Dec 20, 2018 4:03 pm

XPath code for "Most Recent Ancestor", and other keywords

Post by ancleg » Fri Jan 11, 2019 8:53 pm

Also is there any list anywhere of what the keywords are for ranoreXpaths?

https://www.ranorex.com/help/latest/ran ... blueprint/ <- this article says
Examples for axis specifiers are /, //, .., ancestor, and others. They will be described in more detail later in this section.
However Ancestors is never mentioned again. Would love to know how to access the most recent ancestor of a given type.

Thanks.

User avatar
RobinHood42
Posts: 324
Joined: Fri Jan 09, 2015 3:24 pm

Re: XPath code for "Most Recent Ancestor", and other keywords

Post by RobinHood42 » Mon Jan 14, 2019 9:50 am

Hey,

You can use the "ancestor" as shown below:
.../ancestor::list
where "list" is the requested type.

Cheers,
Robin :mrgreen:

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

Re: XPath code for "Most Recent Ancestor", and other keywords

Post by odklizec » Mon Jan 14, 2019 9:57 am

Hi,

Unfortunately, some important xpath information got lost after switching Ranorex user guide to online version. I already reported some lost paragraphs to Ranorex support. In a meantime, I would suggest to download Ranorex 7 setup from Ranorex web and extract offline version of user guide from it ;)

Another thing you might try is to go to Ranorex Spy and after entering '/' character in xpath row, press Ctrl+Space shortcut, which will offer you a list of available adapters and xpath axis operators...
xpath_axis.png
You do not have the required permissions to view the files attached to this post.
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

ahoisl
Certified Professional
Certified Professional
Posts: 192
Joined: Fri Sep 07, 2007 8:16 am

Re: XPath code for "Most Recent Ancestor", and other keywords

Post by ahoisl » Mon Jan 14, 2019 10:24 am

Thank you for your comments!
We are always working on improving the user guide and will also extend this chapter with the missing information. The issue is queued, but it might still take a few weeks to get this specific issue fixed in the user guide.

FYI, the upcoming webinar "Best Practices in Test Automation with Ranorex Studio" will also touch that topic. Reserve your seat here:
https://www.ranorex.com/automated-testing-webinars/

Regards,
Alex
Ranorex Team

ancleg
Posts: 12
Joined: Thu Dec 20, 2018 4:03 pm

Re: XPath code for "Most Recent Ancestor", and other keywords

Post by ancleg » Mon Jan 14, 2019 3:52 pm

RobinHood42 wrote:
Mon Jan 14, 2019 9:50 am
Hey,

You can use the "ancestor" as shown below:
.../ancestor::list
where "list" is the requested type.

Cheers,
Robin :mrgreen:
Issue with this is it finds ALL ancestors of type List. I just want the most recent ancestor. Something like the syntax for div[0] but for ancestor[0]::list would be useful.

@odklizek, thanks for the ctrl-space tip. Didn't know about that.

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

Re: XPath code for "Most Recent Ancestor", and other keywords

Post by odklizec » Mon Jan 14, 2019 3:58 pm

You are welcome. Please upload a Ranorex snapshot of your UI and xpath of the element you would like to find. I'm (almost) sure, there is a way to achieve what you want with correct xpath. It's just complicated to suggest something reliable without seeing the UI ;)
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

ancleg
Posts: 12
Joined: Thu Dec 20, 2018 4:03 pm

Re: XPath code for "Most Recent Ancestor", and other keywords

Post by ancleg » Mon Jan 14, 2019 7:18 pm

We have been able to get the correct item, the issue is we are trying to get the same UI element in two different versions of our software, with the same path. We have one path that works for both but has an ugly OR inside it, which could prevent us from extending the path's value into future versions.

Would prefer not to post snapshots of pre-release stuff publically so PMing you odklizec

sebokdavid90
Posts: 1
Joined: Thu Jul 18, 2019 9:32 am

Re: XPath code for "Most Recent Ancestor", and other keywords

Post by sebokdavid90 » Thu Jul 18, 2019 9:38 am

What I use in these cases is the following:
/ancestor::tag[@class='anything']

where tag = div, list, button, anything you can use in ranorexpath.
and class can be any attribute like class, id, innertext etc.

This finds the ancestor with the specified attribute skipping any ui element in the middle

Hope this helps