Use varaibles to access objects??

Ask general questions here.
lazy9669
Posts: 1
Joined: Fri Jul 02, 2010 2:59 pm

Use varaibles to access objects??

Post by lazy9669 » Fri Jul 02, 2010 3:18 pm

Is it possible to use a variable in an objects path when I'm trying to access it?

In the below example I have a dynamic table with rows named Row011 to Row0x1, where x can vary. I'm trying to make a for loop that will go through all rows, 1 to x and click them.
int i;
Accessible repopath;
			
for(i = 1; i <= Variables.NumRows; i++)
{
    Report.Info("Turning on Link " + i);
    repopath = "repo.FormSM.Row0" + i + "1.Cell";
    repopath.Click();
}
I receive the following error when trying to run this code:
Ranorex.RxPathException: Invalid RxPath 'repo.FormSM.Row011.Cell'. ---> Ranorex.RxPathException: Invalid character at character position 4.
at Ranorex.Core.RxPath..ctor
at Ranorex.Core.Element.op_Implicit
at Ranorex.Accessible.op_Implicit

Is there a way to use different variables in order to access objects? I also have another instance where I'd link to use a string variable in the objects path.

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

Re: Use varaibles to access objects??

Post by Support Team » Mon Jul 05, 2010 10:37 am

Hi,
lazy9669 wrote:Is it possible to use a variable in an objects path when I'm trying to access it?
Please read following post
http://www.ranorex.com/forum/looping-th ... t1347.html
If you adapt this code a little bit, it should work for your solution.

Please also take a look to our screencasts about the RxPath
http://www.ranorex.com/support/screencasts.html

Regards,
Peter
Ranorex Support Team
.
Image