Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to open the CSV file for reading.
Selenium Java
BufferedReader reader = new BufferedReader(new FileReader([1])); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put the file name in quotes causes a compile error.
Using a wrong file name that does not exist.
✗ Incorrect
The file path must be a string literal, so it needs to be in quotes.
2fill in blank
mediumComplete the code to read one line from the CSV file.
Selenium Java
String line = reader.[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'readline' causes a compile error.
Using 'nextLine' is a Scanner method, not BufferedReader.
✗ Incorrect
The correct method to read a line from BufferedReader is readLine() with capital L.
3fill in blank
hardFix the error in splitting the CSV line into values.
Selenium Java
String[] values = line.[1](",");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like 'splitLine' causes errors.
Trying to use 'divide' or 'separate' which are not string methods.
✗ Incorrect
The split method splits a string by a delimiter and returns an array.
4fill in blank
hardFill both blanks to loop through CSV lines and print the first value.
Selenium Java
while (([1] = reader.readLine()) != null) { String[] values = [2].split(","); System.out.println(values[0]); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names causes compile errors.
Using 'reader' or 'values' incorrectly in the split method.
✗ Incorrect
The variable line stores each line read and is used to split into values.
5fill in blank
hardFill all three blanks to close the reader and handle exceptions.
Selenium Java
try { BufferedReader reader = new BufferedReader(new FileReader("data.csv")); String [1]; while (([2] = reader.readLine()) != null) { String[] values = [3].split(","); } reader.close(); } catch (IOException e) { e.printStackTrace(); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names causes errors.
Trying to use 'reader' as the line variable.
✗ Incorrect
The variable line is declared and used consistently to read and split lines.