How to use Xpath Variable in Code Module (example)

Best practices, code snippets for common functionality, examples, and guidelines.
Posts: 16
Joined: Sun May 17, 2015 2:24 pm

How to use Xpath Variable in Code Module (example)

Post by Tzahi » Tue Jan 19, 2016 9:57 am

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
2. Add features menu child xpath (Let’s call it FeaturDD):
RXFeatures.png (14.79 KiB) Viewed 1718 times

/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:
CodeModule.png (11.95 KiB) Viewed 1718 times

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)
Best Regards
Tzahi Caspi