0
0
Selenium Javatesting~10 mins

CSV data reading 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 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'
A"data.csv"
Bdata.csv
Creader.csv
D"read.csv"
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.
2fill in blank
medium

Complete 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'
AnextLine
BreadLine
Cread
Dreadline
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'readline' causes a compile error.
Using 'nextLine' is a Scanner method, not BufferedReader.
3fill in blank
hard

Fix 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'
Asplit
BsplitLine
Cdivide
Dseparate
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.
4fill in blank
hard

Fill 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'
Aline
Breader
Cvalues
Dinput
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names causes compile errors.
Using 'reader' or 'values' incorrectly in the split method.
5fill in blank
hard

Fill 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'
Aline
Dreader
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names causes errors.
Trying to use 'reader' as the line variable.