IList<Ranorex.Cell> iterates over items more than once.

Class library usage, coding and language questions.
kmck
Certified Professional
Certified Professional
Posts: 83
Joined: Fri Jul 12, 2013 2:41 pm

IList<Ranorex.Cell> iterates over items more than once.

Post by kmck » Wed Aug 28, 2013 2:43 pm

Hello,

I am trying to iterate over a list of cell items with a columnindex[0]

Code: Select all

IList<Ranorex.Cell> ProcessList = repo.AgentWelcomeScreen.TabClients.LstProcesses.FindDescendants<Ranorex.Cell>();
             	
    foreach (Ranorex.Cell processItem in ProcessList){
        try{
            if (processItem.ColumnIndex.Equals(0) && !processItem.RowIndex.Equals(-1)){
            //Do stuff here 
            }
        }
        catch (NullReferenceException e){
        	Report.Log(ReportLevel.Info, e.Message + processItem.ToString());
        }
It ends up iterating over the list twice, but I want it only to iterate through the list once. It seems to only do this with the Ranorex.Cell type, whereas if I use a Ranorex.ListItem it will go through the items once.

How can I achieve this with <Ranorex.Cell> IList type?

(Also: I have the try/catch blocks because the IList iterates over the cell headers, which throws an exception "Object reference not set to an instance of an object". Extra bonus if you can help me avoid that :) )

kmck
Certified Professional
Certified Professional
Posts: 83
Joined: Fri Jul 12, 2013 2:41 pm

Re: IList<Ranorex.Cell> iterates over items more than once.

Post by kmck » Thu Aug 29, 2013 7:42 pm

Nobody else has run into this issue?

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

Re: IList<Ranorex.Cell> iterates over items more than once.

Post by Support Team » Fri Aug 30, 2013 1:42 pm

Hi,

In order to analyze the issue in detail could you please send us a snapshot of the specific element?
Following link will show you how to generate a snapshot file: Creating Ranorex Snapshot Files.

It seems that there is one list item including two cell items.

You could use the "break;" statement in order to break out this foreach loop.

In order to avoid the exception you could use a normal for.
You just need to define the loop to start with the second item of the list.

Regards,
Markus
.
Image

kmck
Certified Professional
Certified Professional
Posts: 83
Joined: Fri Jul 12, 2013 2:41 pm

Re: IList<Ranorex.Cell> iterates over items more than once.

Post by kmck » Wed Sep 18, 2013 1:35 pm

Hello Markus,

I thought the table might have had two cell items as well, but when I tried running the same code through the windows task manager processes tab, it also provided a double list of the items.

I've included a snapshot of the task manager processes tab where I am trying to iterate over the first column and extract the names only once.
Attachments
tskmgr.rxsnp
(64.94 KiB) Downloaded 164 times

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

Re: IList<Ranorex.Cell> iterates over items more than once.

Post by Support Team » Thu Sep 19, 2013 4:19 pm

Hello,

If you just want to iterate through the cells of the "ImageName" column you need to search for the cells in that column and not for all cells of the table.
You could use the following code:
Column imageName = "/form[@title='Windows Task Manager']/?/?/table[@controlid='1009']/column[@text='Image Name']";
        	IList<Cell> cells = imageName.FindChildren<Cell>();
        	
        	foreach(Cell cell in cells){
        		
        		Report.Info("Cell: "+cell.Text);
        		
        	}
If you search for all cells within your table you will find each cell twice, since each cell is grouped in a specific row and in a specific column as shown below:
Cells.png
Cells.png (68.91 KiB) Viewed 3120 times
Regards,
Markus
.
Image

kmck
Certified Professional
Certified Professional
Posts: 83
Joined: Fri Jul 12, 2013 2:41 pm

Re: IList<Ranorex.Cell> iterates over items more than once.

Post by kmck » Tue Sep 24, 2013 1:34 pm

Thank you, Markus! Rookie mistake on my part, I appreciate you helping me out :D

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

Re: IList<Ranorex.Cell> iterates over items more than once.

Post by Support Team » Tue Sep 24, 2013 4:13 pm

You're welcome :)!

Regards,
Markus
.
Image