Ross. Thank you for your response. I found the solution, which was to get the count of tbody tags at run time and then get the count of rows within that tbody. This way I was able to loop through all the rows and fetch the data from the cells. Here is the example, I hope it help others:
//Find the results table
WebElement table_element = driver.findElement(By.xpath("//div[@class='wrapper']/table[@class='simple']"));
//Get the count of the tbody's found within the results table
List<WebElement> tbody = driver.findElements(By.xpath("//div[@class='wrapper']/table[@class='simple']/tbody"));
//Get the total of rows in all tbody elements
int myTbody = tbody.size(); //# of tbody elements found within the table
List<WebElement> tr_collection=table_element.findElements(By.xpath("//div[@class='wrapper']/table[@class='simple']/tbody[*]/tr[*]"));
System.out.println("NUMBER OF ROWS IN THIS TABLE = "+tr_collection.size());
String foundProcedureName=null; //Stores procedure name found at run-time for comparison
boolean foundFlag =false; //returns true when expected procedure is found
//Loop through tbody elements
for (int j=1;j<=myTbody;j++){
//Loop through all rows found within the tbody[j] element
for(int i=1; i<=tr_collection.size();i++){
tr_collection=table_element.findElements(By.xpath("//div[@class='wrapper']/table[@class='simple']/tbody["+j+"]/tr"));
//Get the procedure name
foundProcedureName = driver.findElement(By.xpath("//div[@class='wrapper']/table[@class='simple']/tbody["+j+"]/tr["+i+"]/td[5]")).getText();
//System.out.println("procedure found on row: "+i+ " is : "+procedure);
//Compare if found procedure name contains the expected Procedure name
if (foundProcedureName.contains(expectedProcedureName)){
System.out.println("procedure found on tbody: "+j+ " and row number: "+i);
String foundProcedureDate = driver.findElement(By.xpath("//div[@class='wrapper']/table[@class='simple']/tbody["+j+"]/tr["+i+"]/td[2]")).getText();
System.out.println(foundProcedureDate);
/*If procedure name is found then compare is procedure date matches the expected date
If it does then click on the link*/
if(foundProcedureDate.contains(expectedProcedureDate)){
Thread.sleep(1000);
driver.findElement(By.xpath("//div[@class='wrapper']/table[@class='simple']/tbody["+j+"]/tr["+i+"]/td[6]/table/tbody/tr/td/a")).click();
Reporter.log("Found procedure: "+expectedProcedureName+ " for patient: "+patientID);
foundFlag = true;
break;
}
if (foundFlag)
break;
}
if (foundFlag)
break;
}
if (foundFlag)
break;
}
if(!foundFlag){
Assert.assertTrue(foundProcedureName.contains(expectedProcedureName), "Expected procedure: "+expectedProcedureName+ " " +
"with exam date of: "+expectedProcedureDate+ " not found on access patient results screen for patient: "+patientID);
}
}