# Watir-Webdriver working with huge select lists

**URL:** <https://rubytalk.org/t/watir-webdriver-working-with-huge-select-lists/66631>\
**Category:** ruby-talk\
**Created:** [6 November 2012 09:05 UTC](https://rubytalk.org/t/watir-webdriver-working-with-huge-select-lists/66631 "2012-11-06T09:05:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [6 November 2012 09:05 UTC](https://rubytalk.org/t/watir-webdriver-working-with-huge-select-lists/66631/1 "2012-11-06T09:05:18Z")

</div>

Hi,

I'm having trouble understanding the most efficient way to work with a  
select list. I can work alright with smaller ones, but there's a list I  
have to use with over 14 thousand entries, and the value is different  
from the content. When I try to use webdriver to select an item, it will  
use the content.

I need to find a way to select by value, find the entry with a matching  
value and select its content, or pull the entire list into an array so I  
can search it and find the content to go with the value.

For illustrative purposes, with the below I might have only "Java", but  
I wouldn't be able to use the select list without setting it to "Java  
content".

\<select id="entry\_1" name="entry.1.single"\>  
\<option value="Java"\>Java content\</option\>  
\<option value="Ruby"\>Ruby Content\</option\>  
\<option value="C#"\>C# con tent\</option\>  
\<option value="Clojure"\>Clojure conttent\</option\>  
\<option value="Python"\>Python thingy\</option\>

Now, since the list itself is over 14k items (oh god, why?!) even the  
most efficient ways I've tried using Webdriver or even executing  
JavaScript take a long time, and if I do it all in one JavaScript  
command it times out.

This is the best I've been able to come up with so far:

len = b.execute\_script(%Q^ return  
document.getElementsByName('item\_type')[0].length^)  
list = []  
(0...len).each {|num|  
&nbsp;&nbsp;list.push(b.execute\_script(%Q^ return  
document.getElementsByName('item\_type')[0].options[#{num}].text^))  
&nbsp;&nbsp;puts num  
}

This doesn't trigger the JavaScript timeout, but takes 3 minutes.  
Am I missing some obvious way to select this by its value or extract  
everything for comparison?

Thanks

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [6 November 2012 09:10 UTC](https://rubytalk.org/t/watir-webdriver-working-with-huge-select-lists/66631/2 "2012-11-06T09:10:38Z")

</div>

I just realised I'm an idiot... it took laying out my problem like that  
for me to realise that all I need to do is use JavaScript to select the  
option!  
D'oh

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [6 November 2012 12:27 UTC](https://rubytalk.org/t/watir-webdriver-working-with-huge-select-lists/66631/3 "2012-11-06T12:27:27Z")

</div>

Apparently "select\_value" is a method in webdriver. Oops.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
