Page 1 of 1

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

Posted: Fri Jan 11, 2019 8:53 pm
by ancleg
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.

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

Posted: Mon Jan 14, 2019 9:50 am
by RobinHood42
Hey,

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

Cheers,
Robin :mrgreen:

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

Posted: Mon Jan 14, 2019 9:57 am
by odklizec
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

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

Posted: Mon Jan 14, 2019 10:24 am
by ahoisl
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

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

Posted: Mon Jan 14, 2019 3:52 pm
by ancleg
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.

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

Posted: Mon Jan 14, 2019 3:58 pm
by odklizec
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 ;)

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

Posted: Mon Jan 14, 2019 7:18 pm
by ancleg
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

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

Posted: Thu Jul 18, 2019 9:38 am
by sebokdavid90
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