0
0
Selenium Javatesting~10 mins

Excel data reading (Apache POI) in Selenium Java - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a Workbook object from an Excel file input stream.

Selenium Java
FileInputStream file = new FileInputStream("data.xlsx");
Workbook workbook = new [1](file);
Drag options to blanks, or click blank then click option'
AXSSFWorkbook
BFileInputStream
CSheet
DCell
Attempts:
3 left
💡 Hint
Common Mistakes
Using FileInputStream instead of XSSFWorkbook.
Confusing Sheet or Cell classes with Workbook.
2fill in blank
medium

Complete the code to get the first sheet from the workbook.

Selenium Java
Sheet sheet = workbook.[1](0);
Drag options to blanks, or click blank then click option'
AcreateSheet
BgetSheetAt
CgetRow
DgetSheetName
Attempts:
3 left
💡 Hint
Common Mistakes
Using getSheetName which returns a String, not a Sheet object.
Using getRow which is for rows, not sheets.
3fill in blank
hard

Fix the error in the code to read the string value from the first cell of the first row.

Selenium Java
Row row = sheet.getRow(0);
Cell cell = row.getCell(0);
String value = cell.[1]();
Drag options to blanks, or click blank then click option'
AgetNumericCellValue
BtoString
CgetStringCellValue
DgetDateCellValue
Attempts:
3 left
💡 Hint
Common Mistakes
Using getNumericCellValue on a string cell causes runtime errors.
Using toString() returns a generic string, not the cell content.
4fill in blank
hard

Fill both blanks to iterate over all rows and print the first cell's string value.

Selenium Java
for (int [1] = 0; [2] <= sheet.getLastRowNum(); [1]++) {
    Row row = sheet.getRow([1]);
    System.out.println(row.getCell(0).getStringCellValue());
}
Drag options to blanks, or click blank then click option'
Ai
Bj
CrowNum
Dindex
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in the loop condition and increment.
Using a variable name not declared in the loop.
5fill in blank
hard

Fill all three blanks to create a map of row numbers to the string value of the first cell, filtering rows where the cell is not empty.

Selenium Java
Map<Integer, String> dataMap = new HashMap<>();
for (int [1] = 0; [1] <= sheet.getLastRowNum(); [1]++) {
    Row row = sheet.getRow([1]);
    if (row != null && row.getCell(0) != null && !row.getCell(0).getStringCellValue().[2]()) {
        dataMap.put([3], row.getCell(0).getStringCellValue());
    }
}
Drag options to blanks, or click blank then click option'
Ai
BisEmpty
Dtrim
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variables for loop and map key causing errors.
Using trim() instead of isEmpty() for the condition.
Not checking for null rows or cells.