Question

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!

Was it helpful?

Solution 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.

OTHER TIPS

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"

In 2020:

fill_in :reservation_arrival_date, with: '2020-01-01'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top