Table dynamic Search

If you have a debit reference number and credit reference number then you will have to search for each number within its respective “area”. Again, take some time and see what you can pick up. Obviously, you should try not to have the debit reference number run through the credit "area’ and vice versa for the credit reference number running through the debit “area” if they don’t need to.

Maybe like:
driver = DriverFactory.getWebDriver()

def debitRequestedRef = "debit SL No here"
def creditRequestedRef = "credit SL No here"

WebElement table = driver.findElement(By.xpath('id("grdDebitTrn")/tbody'));

List<WebElement> rowsOfTable = table.findElements(By.tagName('tr'));

int rowCnt = rowsOfTable.size();

if (debitRequestedRef != "") {
	Loop:
	for (int cnt = 1; cnt < rowCnt; cnt++) {
		List<WebElement> columnCells = rowsOfTable.get(cnt).findElements(By.tagName('td'));
		
		cellText = columnCells.get(1).findElement(By.tagName('span')).getText();
		
		if (cellText == debitRequestedRef ) {
			columnCells.get(0).findElement(By.tagName('span')).click();
			break Loop;
		}
	}
}

table = driver.findElement(By.xpath('id("grdCreditTrn")/tbody'));

rowsOfTable = table.findElements(By.tagName('tr'));

rowCnt = rowsOfTable.size();

if (creditRequestedRef != "") {
	Loop:
	for (int cnt = 1; cnt < rowCnt; cnt++) {
		columnCells = rowsOfTable.get(cnt).findElements(By.tagName('td'));
		
		cellText = columnCells.get(1).findElement(By.tagName('span')).getText();
		
		if (cellText == creditRequestedRef) {
		
			columnCells.get(0).findElement(By.tagName('span')).click();
			break Loop;
		}
	}
}