Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > reading a line by line from local text file through WATIR

Reply
Thread Tools

reading a line by line from local text file through WATIR

 
 
curious
Guest
Posts: n/a
 
      10-25-2006
I need to process a web page by insert the value in a local text file
line by line each time.

for example, in the code below:
-------------------------------------------------------------------------------------------------
require 'watir'

1.upto(10) do |num|

ie = Watir::IE.start("http://www.test.php")

ie.text_field(:name, "info").set("a_line_from_C\:\\text.txt")

ie.button(:value, "Submit").click

end
---------------------------------------------------------------------------------------------------
I need to make the WATIR code read each line in C:\text.txt file one by
one 10 times. Could anyone tell me how I should adjust the code above
so that this WATIR code read each line in C:\text.txt file one by one
ten times, and process each time with the value in each line in the
text file??

thanks.

 
Reply With Quote
 
 
 
 
Patrick Spence
Guest
Posts: n/a
 
      10-25-2006
curious wrote:
<snip>
> I need to make the WATIR code read each line in C:\text.txt file one by
> one 10 times. Could anyone tell me how I should adjust the code above
> so that this WATIR code read each line in C:\text.txt file one by one
> ten times, and process each time with the value in each line in the
> text file??


Watir has very little to with it, you've already got the code to
populate the textbox and click the "Submit" button. The question is how
do you open a file and read each line. The following should do it.


file = File.open("c:/text.txt", "r")
lines = file.readlines()

#-- make 10-passes thru this loop
1.upto(10) {

#-- process each element in the array
0.upto(lines.length - 1) {|j|
ie.text_field(:name, "info").set(lines[j])
ie.button(:value, "Submit").click
}

}

file.close()
lines.clear()

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading LAST line from text file without iterating through the file? Robin Wenger Java 191 03-26-2011 06:19 PM
Watir: How to return a Watir::IE object for an existing IE? Anukul Singhal Ruby 1 05-15-2008 04:57 PM
passing parameter to WATIR through command line curious Ruby 1 10-29-2006 06:55 PM
copying the file in local hard drive to the text field in the web using WATIR michael Ruby 1 10-15-2006 10:00 AM
uploading local file into text_field using watir michael Ruby 7 08-09-2006 02:05 PM



Advertisments