Page 1 of 1

Loop through all items when RxPath finds more than one item

Posted: Thu Jul 18, 2013 10:50 am
by Christoph
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

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

Posted: Fri Jul 19, 2013 2:16 pm
by Support Team
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)

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

Posted: Fri Jul 19, 2013 2:35 pm
by Christoph
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

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

Posted: Tue Aug 13, 2013 2:22 pm
by Christoph
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

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

Posted: Fri Aug 16, 2013 5:39 pm
by Support Team
Hello,

Thanks for posting your solution :-)

Regards,
Markus (T)