I aim to extract data from the initial row, execute an operation on it, record the outcome, then proceed to the subsequent rows until all the data in the Excel file has been processed.
Here are some queries I have:
- Why are the iterators not functioning as expected?
- Why isn't Selenium's
driver.findElement
performing its intended task?
Primary Program
@Test
public void test() throws Exception {
String filePath = "default.xlsx";
DataHelper.setExcelFile(filePath, "sheet1");
XSSFRow row;
XSSFCell cell;
boolean flag = true;
XSSFSheet sheet = ExcelWSheet;
Iterator rows = sheet.rowIterator();
while (rows.hasNext()) {
row = (XSSFRow) rows.next();
Iterator cells = row.cellIterator();
List <String> obj = new ArrayList<String>();
while (cells.hasNext()) {
cell = (XSSFCell) cells.next();
String cellData = cell.getStringCellValue();
if(flag)
{
driver.findElement(By.id("text")).sendKeys(cellData);
driver.findElement(By.id("text")).click();
driver.findElement(By.id("text")).clear;
}
}
}
}
DataHelper.java
public class DataHelper {
public static XSSFSheet ExcelWSheet;
private static XSSFWorkbook ExcelWBook;
private static XSSFCell cell;
private static String filePath;
public static void setExcelFile(String filePath, String SheetName) throws Exception {
path = filePath;
FileInputStream ExcelFile = new FileInputStream(filePath);
ExcelWBook = new XSSFWorkbook(ExcelFile);
ExcelWSheet = ExcelWBook.getSheet(SheetName);
}
}
Excel Data
Email, Password
hello, 123
hello1, 123