3

I'm new to FireWatir and having some issues changing a selection in a select list. Here's what the HTML looks like:

<div id="softwarelist">  
<select name="TDSOFTWARE" style='width:191;'>  
<option value="QFX">Quicken 2004 or newer-Windows  
<option value="QIF">Quicken 2003 or older-Windows   
<option value="OFX">Microsoft Money 98 or newer  
<option value="QIF">Microsoft Money 97 or older  
<option value="CSV">Microsoft Excel           
</select>  
</div>  

I need to change the selection to CSV.

Here's the line in my script where I am stuck:

browser.div(:id, "softwarelist")

I've sort of randomly tried various methods, but (obviously) none have worked. Using the method 'show_all_objects', like so:

puts browser.div(:id, "softwarelist").show_all_objects

I get a list of all the various formats... that leads me to believe I am in the right ballpark at least, but really I have no idea as I am new to working with FireWatir.

Can anyone point me in the right direction?

Željko Filipin
  • 56,372
  • 28
  • 94
  • 125
phil
  • 33
  • 2

2 Answers2

3

Something like this should work (not tested):

browser.select_list(:name, "TDSOFTWARE").set("Microsoft Excel")

For more information take a look at Selection Boxes page at Watir Wiki.

Željko Filipin
  • 56,372
  • 28
  • 94
  • 125
  • 1
    That worked! Also, thanks for the link. I somehow didn't find that page when I was struggling yesterday. – phil Mar 11 '11 at 03:20
  • Thanks for accepting the answer. :) I plan to write a book on Watir, so documentation should be better soon. Feel free to take a look: https://github.com/zeljkofilipin/watirbook – Željko Filipin Mar 11 '11 at 08:44
2

Your problem is that you are trying to treat the div, which contains the selection list, as if it was the selection list. So you are trying to manipulate the wrong object. you are 'close' because that's the outer container around the list, so show_all_objects will report on the list, which is inside that div.

the code in Zeljko's answer ought to work for you.

Chuck van der Linden
  • 6,660
  • 2
  • 28
  • 43