Using Dropdowns in Watir Webdriver

I had been having some issues getting a dropdown to select a value using the Watir Webdriver and I wanted to briefly write up what I was doing verses what I should have been doing.

In my specific case I wanted to use Watir to drive a date selection using the jQuery datepicker so I inspected the elements and found a class I could latch onto to grab the year dropdown.

select(:class, 'ui-datepicker-year').select('2006')

I thought this would work, but it was telling me that instead of a symbol it was expecting an array. I am guessing this is because out of context it doesn't know if I mean a select element or I want to select something.

The fix was to chain my select with a parent element, like so:

div(:class, 'ui-datepicker-title').select(:class, 'ui-datepicker-year').select('2006')

Now Watir knows that .select means a select box and not to select something.

If you are interested in finding out more I have written up a short blog post about controlling the jQuery datepicker in Watir.

Recent posts View all

Talk CSS

FrontEnders - Web Performance

Sharing some of my thoughts on a FrontEnders meetup on the topic of Web Performance

Conferences

Tips for how to ask for time off to attend conferences

Asking for time off to attend a conference can be nerve-racking, these tips will get you closer to attending the conferences you're interested in.