8

I have a reservation search form that contains the following date_field helper:

<%= date_field(:reservation, :arrival_date) %>

How do I select a specific date for this date_field tag using Capybara?

I tried select "2014-01-01", from: "reservation_arrival_date" in my spec but I get a Capybara::ElementNotFound: error when running the spec.

Thanks in advance!

Adler Santos
  • 365
  • 5
  • 19

3 Answers3

10

As stated in documentation, date_field will not yield a <select> tag but an <input type='date'> this is why you cannot use Capybara::Node::Actions#select.

Instead just treat it as a regular input field:

fill_in "reservation_arrival_date", with: "2014/01/01"
mdemolin
  • 2,514
  • 1
  • 20
  • 23
3

In 2020:

fill_in :reservation_arrival_date, with: '2020-01-01'
Matt Budz
  • 193
  • 1
  • 11
2

Instead of finding a way to click and select a date in the date_field tag, I instead did the following:

page.find('#reservation_arrival_date').set("2014-01-01")

This works really well and I find this approach very simple. But I'm not sure how "awkward" this may seem for an integration test.

Adler Santos
  • 365
  • 5
  • 19