Forum: Ruby Watir-Webdriver working with huge select lists.

Posted by Joel Pearson (virtuoso)
on 2012-11-06 10:05
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|
  list.push(b.execute_script(%Q^ return
document.getElementsByName('item_type')[0].options[#{num}].text^))
  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 by Joel Pearson (virtuoso)
on 2012-11-06 10:10
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 by Joel Pearson (virtuoso)
on 2012-11-06 13:27
Apparently "select_value" is a method in webdriver. Oops.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.