Select_list WATIR codes

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()

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.

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:

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()

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()

chomp:
http://www.rubycentral.com/book/ref_c_string.html#String.chomp

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs