Skip to content

Instantly share code, notes, and snippets.

@BarnabeD
Forked from lbspen/gist:5674563
Created February 26, 2021 09:13
Show Gist options
  • Save BarnabeD/1a73397554fc09b208cce98af75e649c to your computer and use it in GitHub Desktop.
Save BarnabeD/1a73397554fc09b208cce98af75e649c to your computer and use it in GitHub Desktop.
Select date and time for capybara-rspec from rails forms
def select_date(date, options = {})
field = options[:from]
base_id = find(:xpath, ".//label[contains(.,'#{field}')]")[:for]
year, month, day = date.split(',')
select year, :from => "#{base_id}_1i"
select month, :from => "#{base_id}_2i"
select day, :from => "#{base_id}_3i"
end
def select_time(hour, minute, options = {})
field = options[:from]
base_id = find(:xpath, ".//label[contains(.,'#{field}')]")[:for]
select hour, :from => "#{base_id}_4i"
select minute, :from => "#{base_id}_5i"
end
@BarnabeD
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment