Search code examples
rubymechanizemechanize-ruby

Filling out calendar with Mechanize?


I want to fill out the calendar date field for www.vegas.com/lasvegastraveldeals.

So far I can't seem to get the value method to work. Here is my code:

require 'mechanize'

agent = Mechanize.new
page = agent.get('http://www.vegas.com/lasvegastraveldeals/')
vegas_form = page.form('gs')
vegas_form.q = 'DFW'
departure = vegas_form.field_with(:id => 'departureDatec12')
departure.value = "05/16/2014"
pp page

I get this error:

vegas_scraper.rb:9:in `<main>': undefined method `value=' for nil:NilClass (NoMethodError)

Any suggestions?


Solution

  • If the field name is departureDate then this should work:

    form['departureDate'] = '05/16/2014'