# Select\_list WATIR codes

**URL:** <https://www.ruby-forum.com/t/select-list-watir-codes/75366>\
**Category:** Ruby\
**Created:** [November 9, 2006, 1:12pm UTC](https://www.ruby-forum.com/t/select-list-watir-codes/75366 "2006-11-09T13:12:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![curious](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6bbea6/32.png) [@curious](https://www.ruby-forum.com/u/curious)\
**Post date:** [November 9, 2006, 1:12pm UTC](https://www.ruby-forum.com/t/select-list-watir-codes/75366/1 "2006-11-09T13:12:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![curious](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6bbea6/32.png) [@curious](https://www.ruby-forum.com/u/curious)\
**Post date:** [November 9, 2006, 1:16pm UTC](https://www.ruby-forum.com/t/select-list-watir-codes/75366/2 "2006-11-09T13:16:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![curious](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6bbea6/32.png) [@curious](https://www.ruby-forum.com/u/curious)\
**Post date:** [November 9, 2006, 1:30pm UTC](https://www.ruby-forum.com/t/select-list-watir-codes/75366/3 "2006-11-09T13:30:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![curious](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6bbea6/32.png) [@curious](https://www.ruby-forum.com/u/curious)\
**Post date:** [November 9, 2006, 4:31pm UTC](https://www.ruby-forum.com/t/select-list-watir-codes/75366/4 "2006-11-09T16:31:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![curious](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6bbea6/32.png) [@curious](https://www.ruby-forum.com/u/curious)\
**Post date:** [November 9, 2006, 4:25pm UTC](https://www.ruby-forum.com/t/select-list-watir-codes/75366/5 "2006-11-09T16:25:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![curious](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6bbea6/32.png) [@curious](https://www.ruby-forum.com/u/curious)\
**Post date:** [November 9, 2006, 6:51pm UTC](https://www.ruby-forum.com/t/select-list-watir-codes/75366/6 "2006-11-09T18:51:47Z")

</div>

chomp:  
[http://www.rubycentral.com/book/ref\_c\_string.html#String.chomp](http://www.rubycentral.com/book/ref_c_string.html#String.chomp)
