Is there a way to edit the RanorexPath in C#?

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

Is there a way to edit the RanorexPath in C#?

Post by QATest879 » Mon Aug 30, 2021 7:59 pm

This is a question regarding RanoreXPath.

In summary, I need to directly call the RanoreXPath in my code so I can replace the innertext with a variable. For example the path is usually like //div[@innertext='Options'] but I want to replace 'Options' with a variable, because it needs to change based on the context. Is that possible? I haven't been able to directly access RanoreXPaths in the code before so I'm not sure how to do it.

Is there anyway to call a RanorexPath like this?
For example is there a way to do: repo.//div[@innertext=var].Click();
Where I am clicking on the actual path (with a variable in it) rather than a static Element, so that way I can change it depending on the variable?

Thank you.

User avatar
Posts: 478
Joined: Fri Jul 15, 2016 1:35 pm

Re: Is there a way to edit the RanorexPath in C#?

Post by Stub » Tue Aug 31, 2021 7:55 am

In your repository, look at the Variables... button. You can create a variable that is referenced by the repository item thusly:


Then you just set the repository variable MyVariableName to "Options" or whatever.

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

Re: Is there a way to edit the RanorexPath in C#?

Post by odklizec » Tue Aug 31, 2021 8:24 am


I would personally avoid referencing xpaths directly in code, because this practice makes the solution messy and potentially unmaintainable in a long run. So I would use Stub's suggestion and eventually, pass the repo element to code via mathod's parameter. If you insists on using xpath in code, then you must do it like this:

Code: Select all

Ranorex.DivTag searchElement =  repo.FindSingle<Ranorex.DivTag>(".//div[@innertext='" + varName + "']",120000);
searchElement .Click(); 
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