How can I read a CSV file in Selenium using Webdriver?

0 votes
How can I read a CSV file in Selenium using Webdriver?
Jul 16 in Selenium by Trisha
119 views

1 answer to this question.

0 votes

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("   ");
     
    
}

}

}
answered Jul 17 by Abha
• 27,180 points

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer

How can I clear the text in a text box using Selenium WebDriver?

Hello Akriti, you can clear the text ...READ MORE

answered May 29 in Selenium by Anvi
• 13,960 points
294 views
0 votes
1 answer

How can I download the *.jar file from http:// seleniumhq.org using selenium WebDriver?

For Selenium Standalone Server use this: profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/java-archive"); and ...READ MORE

answered Apr 9, 2018 in Selenium by Martin
• 4,220 points
601 views
0 votes
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,110 points
933 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
1,114 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
856 views
0 votes
1 answer
0 votes
1 answer

How can I send some data to a Prompt Alert box using Selenium Webdriver?

Hey Abhishek, you can use sendKeys() method ...READ MORE

answered Jul 2 in Selenium by Abha
• 27,180 points
78 views