Reputation: 405
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!
Upvotes: 8
Views: 6455
Reputation: 2443
In 2023:
fill_in "Reservation arrival date", with: Date.today
Upvotes: -1
Reputation: 2534
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"
Upvotes: 10
Reputation: 405
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.
Upvotes: 2