Hey Trisha, you can read a CSV file in Selenium opencsv. OpenCSV is a third-party API used to easily read data from a CSV file. Following example shows how to use it:
import java.io.FileReader;
import java.util.Iterator;
import java.util.List;
import au.com.bytecode.opencsv.CSVReader;
public class ReadCSVFile {
public static void main(String[] args) throws Exception {
CSVReader reader = new CSVReader(new FileReader("C:\\Users\\Abha_Rathour\\Desktop\\demo.csv"));
List<String[]> list=reader.readAll();
System.out.println("Total rows which we have is "+list.size());
// create Iterator reference
Iterator<String[]>iterator= list.iterator();
// Iterate all values
while(iterator.hasNext()){
String[] str=iterator.next();
System.out.print(" Values are ");
for(int i=0;i<str.length;i++)
{
System.out.print(" "+str[i]);
}
System.out.println(" ");
}
}
}