It's actually pretty simple if you're just using a CSV file. I don't
have my code in front of me at the moment, but I use a CSV file to
store information for a login test.

Basically, since all CSV is is "comma separated", you just open the
file like normal in ruby, read each line, and use .split to get an
array with each value.

fin ="C:\File\Path\Filename.csv","r")
fin.each_line do |line|
     values = line.split(",")
     #Do stuff with values here

for every line in the file, you will end up with an array of each
value on that line.
To write to a CSV file, just do the opposite. Every time you want to
write a line, add commas between your values
(Say that line[] is an array with one line of values you want to add
in a CSV file):

fout ="C:\File\Path\OutputFilename.csv","w")
line.each do |value|
     fout.print "#{value},"
print "\n"

You could create a 2 dimensional array with all the data you want to
put into the CSV file and run the loop I just showed you within
another loop for each line:

fout ="C:\File\Path\OutputFilename.csv","w")
allvalues.each do |line|
     line.each do |value|
          fout.print "#{value},"
     print "\n"

If you want to add the results to the end of the file rather than
rewriting whatever was there already, change the "w" to "a" in the line, that will start writing at the end of the file rather
than the beginning.

Hope that helps, don't hesitate to ask more questions if you have


On Jul 25, 8:03 am, RAM <> wrote:
> Hi all........I am very new to Watir....anybody here knows how to
> import value from  .CSV files and Export Results into an .CSV file in
> Watir????.
> Please reply and provide links if similar subject is already posted.
You received this message because you are subscribed to the Google Groups 
"Watir General" group.
To post to this group, send email to
Before posting, please read the following guidelines:
To unsubscribe from this group, send email to
For more options, visit this group at

Reply via email to