Controlling a jQuery datepicker with Watir

Using a jQuery datepicker with the Watir Webdriver - example code

In my last post I talked about some issues using a dropdown with Watir, the context I was using that in was to complete a jQuery datepicker field that contained both a year and month dropdown.

In case anyone needs the code to be able to do this with Watir Webdriver here it is;

@title = div(:class, 'ui-datepicker-title')
text_field(:class, 'datepicker').click
@title.select(:class, 'ui-datepicker-year').select_value('2006')
@title.select(:class, 'ui-datepicker-month').select('Jan')
table(:class, 'ui-datepicker-calendar').a(:class, 'ui-state-default').click

@title is just a container for the div that contains it.

The two lines with .select will change the value of the year and month dropdowns, there is an change event associated with these inside of jQuery so it will update the calendar automatically for you.

The final line is a bit of a hack because each day doesn’t have a unique id or class, in my test I didn’t really care about the day so I just picked the first standard weekday but you could use :index, 5 or something with the a function and play about to pick the appropriate day.

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.