How to get one of few elements found for RxPath by number

Class library usage, coding and language questions.
Oksana
Posts: 64
Joined: Tue Jan 15, 2013 10:20 am

How to get one of few elements found for RxPath by number

Post by Oksana » Wed Oct 09, 2013 11:23 am

Hello,

There is RxPath expression (e.g. container[@platformclass=$name][$number]) that returns few elements. I need to get one of the results by its number.

It perfectly works in RxPath Editor and elements can be found.
But when I try to get element from code (before it, set values for $name and $number) it fails.

I suspect that the reason is that all repository variables are saved as string and in result RxPath become something like this:

container[@platformclass='class_name']['4']

instead of

container[@platformclass='class_name'][4]

Do you have any idea how to get one of the found elements by number?

Thanks,
Oksana

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: How to get one of few elements found for RxPath by number

Post by krstcs » Wed Oct 09, 2013 1:30 pm

In your usercode file, parse the number into an "int" type.

Code: Select all

int myNumber = int.Parse(stringNumber);
Shortcuts usually aren't...

Oksana
Posts: 64
Joined: Tue Jan 15, 2013 10:20 am

Re: How to get one of few elements found for RxPath by number

Post by Oksana » Wed Oct 09, 2013 1:44 pm

Maybe, I've misunderstood something...

In repository I have:

variable:
number

element with RxPath:
MyElement:
container[$number]

In code in order to get some element by number:
int number = 2;
repo.number = number.ToString();//repo - is an instance of repository
//if ToString() is missed, error message appears
MyElement.Touch();//here I have to get specific element

So, how/where can I initialize repository variable with int not string value?

Thanks

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

Re: How to get one of few elements found for RxPath by number

Post by Support Team » Thu Oct 10, 2013 3:01 pm

Hello,

I am afraid but repository variables are created as string value not as int value.
You would need to parse your string to int and vice versa.
The 'ToString()' method is needed to convert your int value to a string value.

Regards,
Markus (T)
.
Image