0
0
Selenium Javatesting~20 mins

Excel data reading (Apache POI) in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Excel Data Reading Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Apache POI code snippet reading Excel?
Given the following Java code snippet using Apache POI to read an Excel file, what will be printed to the console?
Selenium Java
FileInputStream fis = new FileInputStream("data.xlsx");
Workbook workbook = WorkbookFactory.create(fis);
Sheet sheet = workbook.getSheetAt(0);
Row row = sheet.getRow(1);
Cell cell = row.getCell(2);
System.out.println(cell.getStringCellValue());
workbook.close();
fis.close();
ANullPointerException at getCell
BFileNotFoundException
CNumberFormatException
D"TestValue"
Attempts:
2 left
💡 Hint
Check the cell type and the row/column indices carefully.
assertion
intermediate
1:30remaining
Which assertion correctly verifies the Excel cell value?
You read a cell value from Excel using Apache POI and want to assert it equals "Pass" in a Selenium Java test. Which assertion is correct?
Selenium Java
String actualValue = sheet.getRow(0).getCell(1).getStringCellValue();
AassertTrue(actualValue == "Pass");
BassertEquals("Pass", actualValue);
CassertFalse(actualValue.equals("Pass"));
DassertNull(actualValue);
Attempts:
2 left
💡 Hint
Use the correct assertion method for string equality in Java.
🔧 Debug
advanced
2:30remaining
Why does this Apache POI code throw NullPointerException?
This code throws NullPointerException at runtime. What is the most likely cause?
Selenium Java
Workbook wb = WorkbookFactory.create(new FileInputStream("test.xlsx"));
Sheet sh = wb.getSheetAt(0);
Row r = sh.getRow(5);
Cell c = r.getCell(3);
String val = c.getStringCellValue();
System.out.println(val);
ARow 5 does not exist in the sheet, so getRow(5) returns null.
BCell 3 is numeric, so getStringCellValue() throws NullPointerException.
CWorkbookFactory.create throws NullPointerException if file missing.
DFileInputStream is not closed causing NullPointerException.
Attempts:
2 left
💡 Hint
Check which object is null before calling methods on it.
locator
advanced
2:00remaining
Which locator is best to find the Excel file for reading in Selenium Java?
You want to load an Excel file named "data.xlsx" located in the "resources" folder inside your project root. Which code correctly locates the file for Apache POI reading?
AFileInputStream fis = new FileInputStream(System.getProperty("user.dir") + "/resources/data.xlsx");
BFileInputStream fis = new FileInputStream("resources/data.xlsx");
CFileInputStream fis = new FileInputStream("src/resources/data.xlsx");
DFileInputStream fis = new FileInputStream("/resources/data.xlsx");
Attempts:
2 left
💡 Hint
Use absolute path based on project root for reliable file access.
framework
expert
3:00remaining
How to integrate Apache POI Excel reading in a Selenium TestNG framework for data-driven tests?
Which approach correctly integrates Apache POI to provide test data to a TestNG Selenium test method?
AHardcode Excel data inside @Test method and ignore Apache POI.
BRead Excel inside @Test method and use static variables to share data across tests.
CUse @DataProvider method that reads Excel with Apache POI and returns Object[][] for test method parameters.
DUse Selenium WebDriver to open Excel file and read cells via UI automation.
Attempts:
2 left
💡 Hint
TestNG supports data-driven tests via @DataProvider.