How to fix container[@caption contains a date

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
Posts: 28
Joined: Wed Aug 12, 2015 6:44 pm

How to fix container[@caption contains a date

Post by jmchughsmart » Tue Sep 08, 2015 7:41 pm

The container[@caption contains a date that changes every day.

@title='Enter Scripts' and @fulltype='Enter.Prescriptions.ScriptScreen']/container[@type='EnterPanel']/?/?/container[@caption='9/10/15']/?/?/text[@name='formattedTextField']

How can I set '9/10/15' to todays date ??


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

Re: How to fix container[@caption contains a date

Post by odklizec » Wed Sep 09, 2015 9:06 am

Hi and welcome here,

I think you need to start with learning and understanding Ranorex Data Driven approach, described here: ... html#c2985
There is also a nice video tutorial, available here:

Basically, you need to replace that date string with repository variable. So the xpath should look like this...

Code: Select all

@title='Enter Scripts' and @fulltype='Enter.Prescriptions.ScriptScreen']/container[@type='EnterPanel']/?/?/container[@caption=$actualDate]/?/?/text[@name~'formattedTextField']
Then you need to create a Global Parameter (e.g. actualDate), which you need to bind with the previously created repository variable (actualDate). All this is described in the above mentioned tutorials.

Now you need to do some coding.
Create a new Code module and put it in the very first [Setup] section of your test suite. Learn about Setup/Teardown regions here: ... html#c3003
This will make sure the actual date will be set as the very first action in your test. Eventually, you can put the code directly to Program.cs, but I think using Code module is a cleaner way.

Now about the code...
Below code should get the actual system date, modify its format to M/dd/yy format and save it to previously created Global Parameter actualDate, which is connected to repository variable actualDate. Please take it only as a rough sample! I did not test it, so it may require some tweaks. But I'm using something similar in my tests and it works fine.
System.DateTime dateOutput = System.DateTime.Now;
string dateFormat = "M/dd/yy";
string dateOutputStr = dateOutput.ToString(dateFormat);
TestSuite.Current.Parameters["actualDate"] = dateOutputStr;
That's probably all. If you run your test, it should search for xpath with the actual date, instead of hardcoded one. Hope this helps? ;)
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