Action "Touch": Random element

Ask general questions here.
cristiandiaz.mirada
Posts: 1
Joined: Thu Nov 20, 2014 6:01 pm

Action "Touch": Random element

Post by cristiandiaz.mirada » Thu Nov 20, 2014 6:16 pm

Hi,

Is it possible to use "Touch" action so that it selects a different element each time?

Say for example:
//table/container[3]

Where "3" is the ID of one given element I want to "Touch".
Then, having different containers in my application, is there any way I can indicate Ranorex to randomly pick up "3", or "2", or "1" randomly?

A big thank you in advance.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Action "Touch": Random element

Post by Support Team » Fri Nov 21, 2014 11:30 am

Hello,

You will need to create a UserCodeMethod in order to achieve the mentioned behavior.

For example:
Table table = "/table[...]";

IList<Container> myList =  table.FindDescendants<Container>();

//Create new Random number
Random r = new Random();
int random = r.Next(myList.Count -1);

//Touch random entry
myList[random].Touch();
Regards,
Robert
.
Image