Can I update an XPath address dynamically in code?

Ask general questions here.
stapes
Posts: 206
Joined: Wed Sep 16, 2015 10:55 am

Can I update an XPath address dynamically in code?

Post by stapes » Tue Jun 07, 2016 2:50 pm

I have a variable in my Repository defined as:
/mobileapp[@title='com.365agile.enterprise.365Agile-TEST']/form/container[@caption='' and @containertype='LayoutContainer']/container/container/container/container/container/container/table/
container[1]/container/cell/text[@accessibilitylabel=$currentFormName]
Rather than us $currentFormName here, which is described as an Unbound Variable, I would rather use a C# Global Variable, like this:

Code: Select all

public static string GlobalCurrentForm
	    {
	    	get{return _globalCurrentForm ;}
	    	set{_globalCurrentForm =value ;}
	    }
Can I set this 'path' dynamically in my code, so it does not keep showing up on my reports as an Unbound Variable?

I need to use this path to access the control described.

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

Re: Can I update an XPath address dynamically in code?

Post by odklizec » Tue Jun 07, 2016 3:00 pm

Sadly, unless you bind the variable to a data source, it will always show as "unbinded". However, there is already a feature request to disable/hide "unbound variable warning" per variable (in variable editor) in Ranorex feature requests. And the good news is that it's already in planning stage (according to Ranorex support)! So I would recommend to send an email to [email protected] and they will add your voice to the already existing feature request, which may improve request priority ;)
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

rahulkasana
Posts: 1
Joined: Sat Aug 20, 2016 6:56 am

Re: Can I update an XPath address dynamically in code?

Post by rahulkasana » Sat Aug 20, 2016 7:01 am

You can dynamically update your variable in user code modules without needing to bind them to data source.

/mobileapp[@title='com.365agile.enterprise.365Agile-TEST']/form/container[@caption='' and @containertype='LayoutContainer']/container/container/container/container/container/container/table/
container[1]/container/cell/text[@accessibilitylabel=$currentFormName]

if you have your repository instance named as repo, then you can access this variable as below

repo.currentFormName, now you can assign a value you desire for example,

repo.currentFormName="xyz";

once you have assigned the variable your desired value you can now use your element.