Using Dropdowns in Watir Webdriver

How you can go about using dropdowns using the 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

SEO

Google follows URLs in text

Today I learned that Google follows URLs even when they are plain text

Web Dev

Check in with your database

It pays to take a step back and look at how your database is set up every so often. You will often find quick wins and hidden tech debt.