I'm trying to compare the data on my csv file to web table. `
WebElement mytable1 = driver.findElement(By.cssSelector("#dStocks1"));
// To locate rows of table.
List<WebElement> rows_table1 = mytable1.findElements(By.tagName("tr"));
// To calculate no of rows In table.
int rows_count1 = rows_table1.size();
String path = (filePath);
BufferedReader br = null;
String line;
String splitBy = ",(?=([^\"]|\"[^\"]*\")*$)";
br = new BufferedReader(new FileReader(path));
System.out.println("\n CSV data: ");
br.readLine();
while ((line = br.readLine()) != null) {
for (int col = 1; col < line.length();) {
for (int row = 1; row < rows_count1;) {
System.out.println(" ");
String[] cells = line.split(splitBy);
List<WebElement> rows_table2 = mytable1.findElements(By.tagName("tr"));
List<WebElement> Columns_row = rows_table2.get(row).findElements(By.tagName("td"));
int columns_count = Columns_row.size();
System.out.println("Number of cells In Row " + row + " are " + columns_count);
for (int column = 1; column < columns_count; column++) {
String celtext = Columns_row.get(column).getText();
String col1 = cells[col].substring(1, cells[col].length() - 1);
assertEquals(celtext, col1);
System.out.print(" CELL: " + column + " " + col1 +"\n");
br.readLine();
col++;
}
row++;
System.out.println(" ");
}
}
}
`
This is the result `
Number of cells In Row 1 are 9
CELL: 1 Requested
CELL: 2 PO0815454781
CELL: 3 Main Office Stockroom
CELL: 4 09/13/2022
CELL: 5 DR1212475112
CELL: 6 09/20/2022
CELL: 7 TGP
CELL: 8 3,000,000.00
Number of cells In Row 2 are 9
PASSED: export
FAILED: exportRequested
Index 9 out of bounds for length 9
`
The last index of my csv file is '8' but after printing the line.length
it display '115' and that is the problem. My index is out of bounds. Can someone help me with this. Thank you in advance