Loop through all items when RxPath finds more than one item

Class library usage, coding and language questions.
Christoph
Posts: 23
Joined: Wed Jul 11, 2012 6:22 am
Location: Liechtenstein

Loop through all items when RxPath finds more than one item

Post by Christoph » Thu Jul 18, 2013 10:50 am

Here is the situation: I want to loop through each cell in a table column.

To get the column I specified the rxPath this way "whatever/table/row/cell[@accessiblename~'(?i:column header)']" ("column header" is the displayed header of the column). Using this path the Ranorex Spy finds all the cells in the specified column. If I highlight them they all get highlighed.

Given the above rxpath how can I loop through all the elements (I'm using c#) that the Spy would find using the above path? In all my attempts I only managed to geht the header cell of the column.

I don't necessary need to work with the rxPath. It would be fine to work with the repository item that is defined with the above rxPath.

Christoph

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

Re: Loop through all items when RxPath finds more than one item

Post by Support Team » Fri Jul 19, 2013 2:16 pm

Hello,

Is it possible for you to use the 'columnindex' to get your items?
public void getColumn()
{   	
	IList<Cell> cells = Host.Local.Find<Cell>("/form[@name='MyForm']/table/row/cell[@columnindex='1']");´
	foreach (var cell in cells)
	{
		Report.Info(cell.Text);    		
	}     	
}
Regards,
Markus (T)
.
Image

Christoph
Posts: 23
Joined: Wed Jul 11, 2012 6:22 am
Location: Liechtenstein

Re: Loop through all items when RxPath finds more than one item

Post by Christoph » Fri Jul 19, 2013 2:35 pm

Hi Markus,

Thanks for your suggestion which is worth pursuing. Before I create the cell list I woul need to determine the index of the column. I think I can do it so I will try it out. However, I'm off on vacation in a few minutes so it will be a while before I have the chance to do so.

Christoph

Christoph
Posts: 23
Joined: Wed Jul 11, 2012 6:22 am
Location: Liechtenstein

Re: Loop through all items when RxPath finds more than one item

Post by Christoph » Tue Aug 13, 2013 2:22 pm

Hi Markus,

I cannot use the 'columnindex' as the oder of the colums is dynamic so I need to work with the accessible name.

Here my solution:
public void getColumn()  
   {  
      var grid = repo.myPathSoFar.Grid;

      const string headerOfMyColumnInQuestion = "/row/cell[@accessiblename~'(?i:column header)']";
      string rxPath = grid.AbsoluteBasePath + headerOfMyColumnInQuestion;
      
      IList<Cell> cells = Host.Local.Find<Cell>(rxPath);
      if (cells.Count <= 0)
      {
        throw new RanorexException("Header of column in question invalid. (" + headerOfMyColumnInQuestion + "). Please adjust code to correct cell header."); // in case the header got renamed
      }
      foreach (var cell in cells)
      {
        Report.Info(cell.Text);
      }
  }
Christoph

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

Re: Loop through all items when RxPath finds more than one item

Post by Support Team » Fri Aug 16, 2013 5:39 pm

Hello,

Thanks for posting your solution :-)

Regards,
Markus (T)
.
Image