reading a line by line from local text file through WATIR

Discussion in 'Ruby' started by curious, Oct 25, 2006.

  1. curious

    curious Guest

    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.
     
    curious, Oct 25, 2006
    #1
    1. Advertisements

  2. Re: reading a line by line from local text file through WATI

    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/.
     
    Patrick Spence, Oct 25, 2006
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kaushikshome
    Replies:
    4
    Views:
    1,042
    kaushikshome
    Sep 10, 2006
  2. xyz
    Replies:
    3
    Views:
    758
  3. Robin Wenger
    Replies:
    191
    Views:
    3,951
  4. michael
    Replies:
    7
    Views:
    268
    michael
    Aug 9, 2006
  5. michael
    Replies:
    1
    Views:
    170
    Bret Pettichord
    Oct 15, 2006
  6. curious
    Replies:
    1
    Views:
    363
  7. Anukul Singhal
    Replies:
    1
    Views:
    290
    Charley Baker
    May 15, 2008
  8. Replies:
    20
    Views:
    519
    Michele Dondi
    Jan 16, 2005
Loading...