Injecting Javascript into Watir-Webdriver to avoid large objects

I’m trying to extract the currently selected value from a dropdown list
using webdriver. This process is looped many times per webpage for
hundreds of webpages. The problem is, when I use something like this:


driver.select_lists(:class => ‘iteminput’).each do |listy|
p “#{listy.value}”
end


The object is so large that I get a timeout error from webdriver, one of
those “Are you sure you want to continue running this script?”
dialogues. The problem is that the page is over 5MB, and each listbox
contains hundreds of items.

I have tried using XPATH and CSS, and looking at the HTML directly, but
the HTML doesn’t contain the detail of which item is selected.

I think my only chance to make this run now is to execute a Javascript
command which will return all the currently selected values matching the
criteria as a string. The problem is my knowledge of Javascript is
virtually nonexistant, so would anyone be able to point me in the right
direction, or at least let me know if this is possible?

Thanks.

I believe I have found a crude solution, although it needs further
testing to check for efficacy:

b.select_lists(:class=>‘iteminput’).each do |thingy|
p “#{b.execute_script(“return
document.getElementById(’#{thingy.id}’).value”)}”
end

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