Created
September 11, 2015 16:09
-
-
Save mir4a/718d1d6f75b771a467d4 to your computer and use it in GitHub Desktop.
Datepicker helper for Capybara with RSpec tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def click_on_day_at_datepicker(date) | |
d = Date.parse(date) | |
month = d.strftime('%b') | |
day = d.day | |
# XPath select Month switcher | |
xpath_month_switcher_selector = '//div[contains(@class, "datepicker-days") and not(contains(@style,"display:none"))]//th[contains(@class, "datepicker-switch")]' | |
find(:xpath, xpath_month_switcher_selector).click | |
# XPath select particular Month | |
xpath_particular_month_selector = "//div[contains(@class, \"datepicker-months\") and not(contains(@style,\"display:none\"))]//*[text() = \"#{month}\"]" | |
find(:xpath, xpath_particular_month_selector).click | |
# XPath looking for day in calendar with text equals to day at current month | |
xpath_day_selector = "//div[contains(@class,\"datepicker datepicker-dropdown\")]//td[contains(@class, \"day\") and not(contains(@class, \"new\") or contains(@class, \"old\")) and text() = \"#{day}\" ]" | |
find(:xpath, xpath_day_selector).click | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment