How to collect info from multiple cells in grid/table object

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
ppatrick
Posts: 6
Joined: Wed May 15, 2013 9:27 pm

How to collect info from multiple cells in grid/table object

Post by ppatrick » Thu May 23, 2013 11:03 pm

Hi,

I'm a newbie Ranorex user. I'm trying to read multiple rows from the grid/table object. So far I could only read info from one cell. I've checked other post and tried some of the recommended solution such as using FindDescendants in Foreach loop. However it didn't work. Below is my code:

public ValidateSort()
{
// Do not delete - a parameterless constructor is required!

var repo = Shared_ModulesRepository.Instance;
var mRNRow = repo.RETR_objects.SearchPatient.DataPanel.MRNRow0;
var textMaskBox1 = repo.RETR_objects.LayoutControl1.TextMaskBox1;

IList<Row> rows = mRNRow.FindDescendants<Row>();
foreach(Row row in rows){
System.Diagnostics.Debug.WriteLine(mRNRow.Text);
}

System.Diagnostics.Debug.WriteLine("This is a test output message from Patrick");
System.Diagnostics.Debug.WriteLine(mRNRow.Text);
textMaskBox1.Focus();
}

The attachment is the Ranorex snapshot file that contains the table object that I'm trying to access the info inside. Please advice.

Patrick
You do not have the required permissions to view the files attached to this post.

mdgairaud
Posts: 87
Joined: Sun Aug 05, 2012 11:59 am
Location: Bilbao, Spain

Re: How to collect info from multiple cells in grid/table object

Post by mdgairaud » Fri May 24, 2013 10:05 am

Hi,

I use this method to read all the columns and rows inside a table to save the images it contains in every cell:

Code: Select all

IList<Element> miTabla = repo.SomeTableTag.Element.Children;

for (int i = 0; i <= 1; i++)
{
  foreach (Ranorex.Core.Element boton in miTabla[0].Children[i].Children)
  {
    miNewElement = boton.CaptureCompressedImage();
    [...]
  }
}
The for statement loops for every row in the table (in my case 2 rows), and the foreach loops for every column. The element called 'boton' is a exact copy from the one in the current cell.

Replace 'repo.SomeTableTag' with your element's xPath.


hope it helps.


regards,
Mateo.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How to collect info from multiple cells in grid/table object

Post by Support Team » Mon May 27, 2013 1:57 pm

Hi,

Thanks Mateo for your posting, I just wanted to describe an alternative way how this could also work.
I use the data from the snapshot for my small sample.
Container dataPanel = "/form[@controlname='RetrievePatientForm']/container/element/table/container[@accessiblename='Data Panel']";
        	
// In oder to get the rows you could use the following code:
IList<Row> rows = dataPanel.FindChildren<Row>();
        	
foreach(Row row in rows){
        		
        	// Values of the row
        	Report.Info("Row Values: "+row.Element.GetAttributeValue("AccessibleValue"));
        		
        	// Getting the cells of the current row
        	IList<Cell> cells = row.FindChildren<Cell>();
        		
        	foreach(Cell cell in cells){
        			
        		// Text of the current Cell
        		Report.Info("Cell Text: "+cell.Text);
        			
        	}
        		
}
Regards,
Markus

ppatrick
Posts: 6
Joined: Wed May 15, 2013 9:27 pm

Re: How to collect info from multiple cells in grid/table object

Post by ppatrick » Thu Jun 20, 2013 10:02 pm

Thank you!