Page 1 of 1

How to use Xpath Variable in Code Module (example)

Posted: Tue Jan 19, 2016 9:57 am
by Tzahi
Hi All,
I add an issue that was solved by support (Robert Prehm), just sharing it.
for experts:
just add your repo.XpathValue = yourCodeModuleVariable.
for beginners:
I will show how to use Variable in Xpath and then use it in a code module:
1. Browse http://www.ranorex.com/
2. Add features menu child xpath (Let’s call it FeaturDD):
[img]
RXFeatures.png
[/img]

/dom[@caption~'^Automated\ Testing\ Tools\ f']//ul[@class='dropdown-menu page-55-0']//a[@innertext='How It Works']
3. Change 'How It Works’ to Variable (by ranorex spy --> Path Editor, Use the dropdown): FeaturDD
Note: you can see this menu have 3 different optional Variable (tech…. what our ….).
4. Create a Code module to your test case:
[img]
CodeModule.png
[/img]

5. At your code module:
a) Right click Insert New Module Variable, and give it a name: FeaturDD
b) Create an repository instance:
e.g.: var repo = MyCoolRepository.Instance;
c) Insert the variable to the repository
e.g. repo.FeaturDD = FeaturDD;

6. Create any data connector (e.g. excel) with FeaturDD column, and give one of the values: e.g. Technology Support.
Browse to Binding and click on Auto Binding.

Now each TestCase can browse to a different item :D
Special Thanks to Robert 8)