just_add_watir | Advanced recipes for Watir
25Jul/08Off

Q. How do I find the selected element in a combo box?

A. Use the select_list comand in conjunction with the getSelectedItems command
Example html:

<select name="watirCombo">
     <option value="0" selected>(please select:)</option>
     <option value="1">Option 1</option>
     <option value="2">Option 2</option>
     <option value="3">Option 3</option>
     <option value="other">Other</option>
</select>

Example watir:

 @b.goto('http://justaddwatir.com/watir/test_html/tc_0001_0100/test_0021.html')
 combo_items = @b.select_list(:name, "watirCombo").getSelectedItems
 puts combo_items