using normal varaible in XPath

Best practices, code snippets for common functionality, examples, and guidelines.
prasoon.jmit
Posts: 13
Joined: Mon Dec 09, 2019 1:37 pm

using normal varaible in XPath

Post by prasoon.jmit » Wed Dec 18, 2019 7:09 am

I have a user code and for user code I am not able to define repository variable. Can I use normal variable inside XPath as @helptext?

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

Re: using normal varaible in XPath

Post by odklizec » Wed Dec 18, 2019 8:17 am

Hi,

If you are hardcoding xpaths in user code (in Recording module), you must apply the variable like this (where cellCSVValue is the variable):

Code: Select all

var spanItem = selectPopUpItem.FindSingle<Ranorex.SpanTag>(".//span[@class='mat-option' and @innertext~'" + cellCSVValue + "']", Duration.FromMilliseconds(15000));
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

prasoon.jmit
Posts: 13
Joined: Mon Dec 09, 2019 1:37 pm

Re: using normal varaible in XPath

Post by prasoon.jmit » Wed Dec 18, 2019 2:39 pm

Hi,

Thanks for quick response.

My XPath is like "element[@automationid='Test']/?/?/element[@automationid='Cell_User' and @helptext=$varReadOnlyWorkspaceName]"


Can I Use $varReadOnlyWorkspaceName as normal variable in place of repository variable? If yes, than what is the use of Repository variable?

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

Re: using normal varaible in XPath

Post by odklizec » Wed Dec 18, 2019 2:45 pm

Hi,

I'm afraid, I don't quite understand what you are trying to achieve? The xpath you posted in how you have it stored in repo, right? Now what exactly you would like to do with it?
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

prasoon.jmit
Posts: 13
Joined: Mon Dec 09, 2019 1:37 pm

Re: using normal varaible in XPath

Post by prasoon.jmit » Wed Dec 18, 2019 2:56 pm

Hi,

Yes the XPath is stored in Repository.

I have one recording e.g. abc.rxrec. In Recording I have UserCode(Name of method is SelectUser), inside userCode I am accessing the repository item like repo.Cell.Click() (cell is the repository item whose path I have shared in first post). I am planning to use abc.rxrec in multiple projects, so I am thing to make variable inside XPath as bindable so that I can reuse the code.

That's the reason I want to know can I make variable $varReadOnlyWorkspaceName as normal variable and bind it with variable at "SmartFolder" level?

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

Re: using normal varaible in XPath

Post by odklizec » Wed Dec 18, 2019 3:22 pm

Hi,

$varReadOnlyWorkspaceName is normal module variable, so yes, you can bind it to TestCase or SmartFolder data connector or even TC/SF parameter.

Once there is created a module variable (either in action table or repository) and the variable is applied in action table or repository element and the repo element is used in recording module, you should see "unbound variable" in TestSuite, in which the recording module is used. Then you simply bind the variable to TC/SF data connector. The module variable is automatically available also in user code of given recording module.
RepoVars.png
RepoVars.png (96.2 KiB) Viewed 359 times
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

prasoon.jmit
Posts: 13
Joined: Mon Dec 09, 2019 1:37 pm

Re: using normal varaible in XPath

Post by prasoon.jmit » Wed Dec 18, 2019 3:30 pm

Hi,

Thanks a lot for detailed explanation. Most of the things are clear. Just one confusion $testVar as I can see in screenshot is the "Repository Variable", can I use variable which is normal variable not a repository variable?

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

Re: using normal varaible in XPath

Post by odklizec » Wed Dec 18, 2019 3:35 pm

If you mean a recording variable (created in action table via 'Variables' editor), then yes. If you mean a variable created directly in user code, then no. You must create a Recording variable, which is the only way, how to bind module variables with data connectors/parameters.
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

prasoon.jmit
Posts: 13
Joined: Mon Dec 09, 2019 1:37 pm

Re: using normal varaible in XPath

Post by prasoon.jmit » Wed Dec 18, 2019 4:15 pm

Hi,

Thanks a lot. This cleared my doubt .

So what is the advantage of repository variable, if we can achieve same thing using recording variable?

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

Re: using normal varaible in XPath

Post by odklizec » Thu Dec 19, 2019 8:26 am

Hi,

You are welcome.

As for the repository variables, for me, they are the same as recording variables. Once a repository variable is applied in repo element, which is used in recording module, then there is added a new variable also to the list of recording module variables. The only difference is that you don't see all repository variables in the list of recording module variables, but only those, which are actually used in recording module (repo elements with associated repo variables).
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