How to create repository items with a general path?

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
QATest879
Posts: 31
Joined: Fri Jul 02, 2021 2:35 pm

How to create repository items with a general path?

Post by QATest879 » Wed Dec 08, 2021 7:54 pm

After a while of using Ranorex Studio I began to notice that a lot of my repository items have a RanoreXPath something like:

.//container/container[3]/[@type="Example"].

But because the index 3 changed often I figured-out it was possible to do something like:

.//container/?/[@text="Click here"].

And this will create a repo item for something that has the text value of "Click here" and ignore the container index.

So, in general I'm wondering if there's a way to make this even more broad and general? Like, is there a way to create a repository item that clicks on any element in the repo that has the text "Click here"?

And I'm also wondering if there are any resources or links to resources you might have about advanced RanoreXPath customization and all of the different options that can be used. Right now I know how to replace @type with @text and it works, and so I'm wondering what else I can use @ for.

Thank you.

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

Re: How to create repository items with a general path?

Post by odklizec » Thu Dec 09, 2021 7:21 am

Hi,

There is number of webinars and blog posts found at Ranorex
website:
https://www.ranorex.com/resources/
https://www.ranorex.com/automated-testing-webinars/
https://www.ranorex.com/blog/
Simply search for xpath-related articles and videos.

Generally speaking, you can use any attribute available in Spy. You can even use logical operators 'and' and 'or', like
.//container/?/[@text="Click here" or @text="Click there"]
.//container/?/[@text="Click here" and @visible="True"]

Just be careful about generalizing the xpath too much, because it could result in multiple found elements (some of them may be invisible or irrelevant). In case of multiple found elements, Ranorex will always pick and use the first one found, where the first one does not necessarily be the one you want ;)
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

Fergal
Certified Professional
Certified Professional
Posts: 454
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Re: How to create repository items with a general path?

Post by Fergal » Thu Dec 09, 2021 11:31 am

In addition to the helpful links odklizec gave you, you might find this section of the Ranorex User Guide helpful: https://www.ranorex.com/help/latest/ran ... roduction/

Elena_v
Posts: 18
Joined: Tue Jun 25, 2019 4:27 pm

Re: How to create repository items with a general path?

Post by Elena_v » Mon Dec 13, 2021 1:23 pm

I recommend you to use repository variables:
https://www.ranorex.com/help/latest/ran ... n-testing/