select_list WATIR codes..

Discussion in 'Ruby' started by curious, Nov 9, 2006.

  1. curious

    curious Guest

    I have something funny going on with my WATIR. code.

    in the code below, test.txt file has about 50 lines.. for example, line
    number 1 is 'test1', number 2 is 'test2', and so on..

    I am trying to choose this line value in the select box in the web page
    one by one from the local text file and process it.

    in the below code, the line..

    ie.select_list( :name , "leftsegments").select("#{$Guide}")

    is supposed to choose test1 from the select box, which is the first
    line in the test.txt file. Now even though test1 is one of the values
    in the select box, the message says 'there is no 'text1' in the select
    list.

    so I tried the code below again with

    ie.select_list( :name , "leftsegments").select("test1")

    and it works fine..

    what am I doing wrong?? the select box in the web page has more than
    150 values.. maybe too many values to choose from?? is that confusing
    the WATIR code?? but what about the error message that says 'there is
    no test1 in the select list'????

    could anyone help and tell me what I am doing wrong??

    thanks.

    ========================================================================
    require 'watir'

    ie = Watir::IE.start("http://www.testing.com")
    ie.link:)text, "New Page").click
    file = File.open("c:/test.txt", "r")
    lines = file.readlines()
    0.upto(lines.length - 1) {|j|
    $Guide = lines[j]
    ie.button:)name, "choose_segments").click
    ie.select_list( :name , "leftsegments").select("#{$Guide}")
    ie.button:)name, "leftsegmentsButton").click
    }
    file.close()
    lines.clear()
    curious, Nov 9, 2006
    #1
    1. Advertising

  2. curious

    curious Guest

    <select name=leftsegments multiple size=8>

    one more comment.. above is the select HTML on the web page.. does
    multiple size being 8 would have anything to do with the problem I am
    having??

    So I changed the first line in the text file to the first one in the
    select list.. but still the same situation..

    any help will be deeply appreciated..

    thanks.

    curious wrote:
    > I have something funny going on with my WATIR. code.
    >
    > in the code below, test.txt file has about 50 lines.. for example, line
    > number 1 is 'test1', number 2 is 'test2', and so on..
    >
    > I am trying to choose this line value in the select box in the web page
    > one by one from the local text file and process it.
    >
    > in the below code, the line..
    >
    > ie.select_list( :name , "leftsegments").select("#{$Guide}")
    >
    > is supposed to choose test1 from the select box, which is the first
    > line in the test.txt file. Now even though test1 is one of the values
    > in the select box, the message says 'there is no 'text1' in the select
    > list.
    >
    > so I tried the code below again with
    >
    > ie.select_list( :name , "leftsegments").select("test1")
    >
    > and it works fine..
    >
    > what am I doing wrong?? the select box in the web page has more than
    > 150 values.. maybe too many values to choose from?? is that confusing
    > the WATIR code?? but what about the error message that says 'there is
    > no test1 in the select list'????
    >
    > could anyone help and tell me what I am doing wrong??
    >
    > thanks.
    >
    > ========================================================================
    > require 'watir'
    >
    > ie = Watir::IE.start("http://www.testing.com")
    > ie.link:)text, "New Page").click
    > file = File.open("c:/test.txt", "r")
    > lines = file.readlines()
    > 0.upto(lines.length - 1) {|j|
    > $Guide = lines[j]
    > ie.button:)name, "choose_segments").click
    > ie.select_list( :name , "leftsegments").select("#{$Guide}")
    > ie.button:)name, "leftsegmentsButton").click
    > }
    > file.close()
    > lines.clear()
    curious, Nov 9, 2006
    #2
    1. Advertising

  3. curious

    curious Guest

    I did some addtional testing, and i think the problem has something to
    do with the format of the line read by the code..

    I tried other select boxes that surely worked fine.. but once i read
    the choices in the select box from the local text file, then the same
    problem persists.

    could anyone please tell me how I should adjust the format of each line
    read from the local text file so that the WATIR code select each option
    one by one from the text file??

    thanks.

    curious wrote:
    > <select name=leftsegments multiple size=8>
    >
    > one more comment.. above is the select HTML on the web page.. does
    > multiple size being 8 would have anything to do with the problem I am
    > having??
    >
    > So I changed the first line in the text file to the first one in the
    > select list.. but still the same situation..
    >
    > any help will be deeply appreciated..
    >
    > thanks.
    >
    > curious wrote:
    > > I have something funny going on with my WATIR. code.
    > >
    > > in the code below, test.txt file has about 50 lines.. for example, line
    > > number 1 is 'test1', number 2 is 'test2', and so on..
    > >
    > > I am trying to choose this line value in the select box in the web page
    > > one by one from the local text file and process it.
    > >
    > > in the below code, the line..
    > >
    > > ie.select_list( :name , "leftsegments").select("#{$Guide}")
    > >
    > > is supposed to choose test1 from the select box, which is the first
    > > line in the test.txt file. Now even though test1 is one of the values
    > > in the select box, the message says 'there is no 'text1' in the select
    > > list.
    > >
    > > so I tried the code below again with
    > >
    > > ie.select_list( :name , "leftsegments").select("test1")
    > >
    > > and it works fine..
    > >
    > > what am I doing wrong?? the select box in the web page has more than
    > > 150 values.. maybe too many values to choose from?? is that confusing
    > > the WATIR code?? but what about the error message that says 'there is
    > > no test1 in the select list'????
    > >
    > > could anyone help and tell me what I am doing wrong??
    > >
    > > thanks.
    > >
    > > ========================================================================
    > > require 'watir'
    > >
    > > ie = Watir::IE.start("http://www.testing.com")
    > > ie.link:)text, "New Page").click
    > > file = File.open("c:/test.txt", "r")
    > > lines = file.readlines()
    > > 0.upto(lines.length - 1) {|j|
    > > $Guide = lines[j]
    > > ie.button:)name, "choose_segments").click
    > > ie.select_list( :name , "leftsegments").select("#{$Guide}")
    > > ie.button:)name, "leftsegmentsButton").click
    > > }
    > > file.close()
    > > lines.clear()
    curious, Nov 9, 2006
    #3
  4. curious wrote:
    > > could anyone help and tell me what I am doing wrong??
    > > ie.select_list( :name , "leftsegments").select({$Guide}")


    I suspect the trailing newline character; "\n", is what's eating your
    lunch on this. Here's what I cobbled-up and it works just fine...

    file = File.open("test.txt", "r+")
    lines = file.readlines()

    lines.each {|testName|
    ie.select_list:)name, "leftsegments").select(testName.chop!) #--
    notice use of .chop!
    sleep(0.25)
    }

    file.close()
    lines.clear()
    Patrick Spence, Nov 9, 2006
    #4
  5. curious wrote:
    > > could anyone help and tell me what I am doing wrong??
    > > ie.select_list( :name , "leftsegments").select({$Guide}")


    I suspect the trailing newline character; "\n", is what's eating your
    lunch on this. Here's what I cobbled-up and it works just fine...

    file = File.open("test.txt", "r+")
    lines = file.readlines()

    lines.each {|testName|
    ie.select_list:)name, "leftsegments").select(testName.chop!) #--
    notice use of .chop!
    sleep(0.25)
    }

    file.close()
    lines.clear()
    Patrick Spence, Nov 9, 2006
    #5
  6. chomp:
    http://www.rubycentral.com/book/ref_c_string.html#String.chomp

    curious wrote:
    > I did some addtional testing, and i think the problem has something to
    > do with the format of the line read by the code..
    >
    > I tried other select boxes that surely worked fine.. but once i read
    > the choices in the select box from the local text file, then the same
    > problem persists.
    >
    > could anyone please tell me how I should adjust the format of each line
    > read from the local text file so that the WATIR code select each option
    > one by one from the text file??
    >
    > thanks.
    >
    > curious wrote:
    > > <select name=leftsegments multiple size=8>
    > >
    > > one more comment.. above is the select HTML on the web page.. does
    > > multiple size being 8 would have anything to do with the problem I am
    > > having??
    > >
    > > So I changed the first line in the text file to the first one in the
    > > select list.. but still the same situation..
    > >
    > > any help will be deeply appreciated..
    > >
    > > thanks.
    > >
    > > curious wrote:
    > > > I have something funny going on with my WATIR. code.
    > > >
    > > > in the code below, test.txt file has about 50 lines.. for example, line
    > > > number 1 is 'test1', number 2 is 'test2', and so on..
    > > >
    > > > I am trying to choose this line value in the select box in the web page
    > > > one by one from the local text file and process it.
    > > >
    > > > in the below code, the line..
    > > >
    > > > ie.select_list( :name , "leftsegments").select("#{$Guide}")
    > > >
    > > > is supposed to choose test1 from the select box, which is the first
    > > > line in the test.txt file. Now even though test1 is one of the values
    > > > in the select box, the message says 'there is no 'text1' in the select
    > > > list.
    > > >
    > > > so I tried the code below again with
    > > >
    > > > ie.select_list( :name , "leftsegments").select("test1")
    > > >
    > > > and it works fine..
    > > >
    > > > what am I doing wrong?? the select box in the web page has more than
    > > > 150 values.. maybe too many values to choose from?? is that confusing
    > > > the WATIR code?? but what about the error message that says 'there is
    > > > no test1 in the select list'????
    > > >
    > > > could anyone help and tell me what I am doing wrong??
    > > >
    > > > thanks.
    > > >
    > > > ========================================================================
    > > > require 'watir'
    > > >
    > > > ie = Watir::IE.start("http://www.testing.com")
    > > > ie.link:)text, "New Page").click
    > > > file = File.open("c:/test.txt", "r")
    > > > lines = file.readlines()
    > > > 0.upto(lines.length - 1) {|j|
    > > > $Guide = lines[j]
    > > > ie.button:)name, "choose_segments").click
    > > > ie.select_list( :name , "leftsegments").select("#{$Guide}")
    > > > ie.button:)name, "leftsegmentsButton").click
    > > > }
    > > > file.close()
    > > > lines.clear()
    Chris McMahon, Nov 9, 2006
    #6
    1. Advertising

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. Greg  --
    Replies:
    4
    Views:
    2,119
  2. Replies:
    2
    Views:
    2,788
    Malcolm
    Aug 20, 2005
  3. Vikash Kumar
    Replies:
    0
    Views:
    92
    Vikash Kumar
    Nov 29, 2006
  4. curious
    Replies:
    1
    Views:
    100
    curious
    Dec 5, 2006
  5. Anukul Singhal
    Replies:
    1
    Views:
    154
    Charley Baker
    May 15, 2008
Loading...

Share This Page