msmith1114
msmith1114

Reputation: 3231

Capybara DayPickerInput selection?

Has anyone had any luck in figuring out how to use the react library https://react-day-picker.js.org/docs/input/

With Capybara/Selenium? Unfortunately it doesn't allow simply typing in the text such as MM/DD/YYYY like most date-pickers. This only allows mouse selection.

Or is specifically setting the value basically the only way to do so?

Upvotes: 0

Views: 93

Answers (1)

Thomas Walpole
Thomas Walpole

Reputation: 49910

Without an example which shows the actual configuration of react-day-picker you're dealing with it's impossible to say exactly what you need to do, but the general rule is if you are testing the sites functionality then do what a user would need to do. In your case that may mean click on the forward/back month arrows until you get to the desired month, then click on the specific day element. Assuming the date you want to select is in the future (September 20, 2019) it would be something like

caption = find('.DayPicker-Caption')
until caption.has_text?('September 2019', wait: 0) do
  current_month = caption.text
  find('.DayPicker-NavButton--next').click
  # wait for month to change
  expect(caption).not_to have_text(current_month)
end
find('.DayPicker-Day', exact_text: '20').click

If you're not actually testing functionality (web scraping, etc) then you can use execute_script to call the react-day-picker JS API and set a specific date.

Upvotes: 1

Related Questions