From: Justin Collins Date: 2006-05-25T15:38:38+09:00 Subject: Re: Multiple Arrays Justin Collins wrote: > eric tabora wrote: >> As you can probably tell, I'm a noob. I'm working with a program >> called Watir written in ruby. I'm trying to use two txt documents to >> populate two different text fields. I'm able to create the arrays, >> but having trouble populating the text fields properly before >> Submitting. The first field 'Width' populates correctly by placing >> one line at a time. But the second places all values in the array >> into the field. Any help would be greatly appreciated. >> >> > Hi Eric, > >> Here's what I have: >> >> def size_entry >> >> size_array = IO.readlines("OneOffSizes1.txt") >> size_array2 = IO.readlines("OneOffSizes2.txt") >> >> > So far so good. (Assuming the arrays are the same size). You might try > more descriptive names, too. >> size_array.each_with_index do |size_array,i| >> > Here is where you start having problems. size_array.each_with_index > passes in two variables, the /object/ and its /index./ You are using > the same variable for the object as the array. Try something else like: > size_array.each_with_index do > |width, index| > >> $ie.textField(:name, "width").set("#{size_array}") >> >> $ie.textField(:name, "height").set("#{size_array2}") >> > The reason why it works for 'width' is because you are iterating over > size_array on the outside, but on the inside you are using the > individual values. But for size_array2 you are using the entire array! > What I think you are trying to do here is iterate through both arrays > in parallel. > Try something like: > > $ie.textField(:name, "width").set("#{width}") > $ie.textField(:name, > "height").set("#{size_array2[index]}") >> $ie.button(:value, "Submit").click >> >> end >> >> end #size_entry >> >> >> > > So the whole thing would look like: > > def size_entry > > width_array = IO.readlines("OneOffSizes1.txt") > height_array2 = IO.readlines("OneOffSizes2.txt") > > width_array.each_with_index do |width, index| > > $ie.textField(:name, "width").set("#{width}") > > $ie.textField(:name, "height").set("#{height_array[index]}") > > $ie.button(:value, "Submit").click > end > > end > > end #size_entry > > > Hope that helps. > > -Justin > Oops - height_array2 => height_array. -Justin