csvRead (file name) - Selenium IDE command

The purpose of csvRead is to read data from a CSV file. Each macro loop reads one line of the CSV file and makes the data in the available with the ${!COL1}, ${!COL2},... internal variables.

Important: To submit more than just the first line of the CSV file, you must start the macro with the LOOP button. Each loop reads one line of the CSV. The line read is based on the value of the ${!LOOP} counter variable. If you make the loop run from 5 to 10, it will read lines 5 to 10 from the CSV file. Another option is to embed the CSVRead command inside a while loop with the internal vars !csvReadStatus and !csvReadLineNumber as shown in the DemoCsvReadWithWhile demo macro.

CSV Manager: Import (load) and export (save) CSV files from the Kantu extension
Use the CSV Manager tab to import (load) and export (save) CSV files to and from the Kantu extension. Importing CSV files first is required because browser extensions can not read from the hard drive directly. But with our Kantu FileAccess XModule kantu can read CSV directly, see the next paragraph:

Reading CSV files directly from the hard drive

If you have the Kantu FileAccess XModule installed, you can switch the macro storage mode to Hard-Drive Storage. This will also redirect all CSV read and write operation directly to the hard drive. By default, CSV files are then stored in the kantu/datasources folder. In other words: Kantu reads CSV data then directly from files - and you no longer need to import CSV files before using them. This also allows to easily share macros, images and CSV files between team members.

FAQ: How can I use commas inside the CSV file text (not as a separator)?

User question: Kantu uses comma as a separator, but I need sometimes to use comma in the text (not as a separator); how can i do this?
Answer: Enclose the field in quotes, e.g. use field1,field2,"fi,e,ld3",field4. And to include a single quote symbol " in a field it will be encoded as "", and the whole field will become """".

csvRead Example

This short example below reads names from a CSV file called "user.csv" and then fills the data into a form using the ${COL1} and ${COL2} internal variable. The CSV file has to be loaded in the Kantu extension on the CSV tab to the local browser storage, it is not read from file.

Command Target Pattern/Text
open https://a9t9.com/
csvRead user.csv
type id=firstname ${!COL1}
type id=lastname ${!COL2}

!csvReadMaxRow - read the last line of a CSV file

V2.7 and later: In some cases you may need to now how many lines are in a CSV file, or you want to read the last (most recently added) line of a CSV file. In both cases the internal variable !csvReadMaxRow can help. After the first csvRead, this value is set the number of lines in the CSV. This the example below we use it to read the last line of from a CSV file called "user.csv". We do this by setting !csvReadLineNumber to csvReadMaxRow and then run csvRead again.

Command Target Pattern/Text
csvRead user.csv
store ${!csvReadMaxRow} !csvReadLineNumber
csvRead user.csv
type id=firstname ${!COL1}

Works in

Kantu for Chrome Selenium IDE

Related Demo Macros

DemocsvRead

See also

csvSave, storeEval, Web Automation Extension User Manual, Selenium IDE commands, Classic Firefox Selenium IDE.

Anything wrong or missing on this page? Suggestions?

...then please contact us.

Kantu Selenium IDE for Chrome and Firefox - Web Test Automation
Subscribe to the a9t9 automation software newsletter . We'll send you updates on new releases that we're working on.