3

Chrome / Selenium appears to have a different format for some input types between locales. For example, the date picker (i.e. input type="date") for the is formatted as mm/dd/yyyy for US and yyyy-mm-dd for Canada. This makes it difficult to write specs that work on machines with different locales. For example:

find("input[type='date']").set("12/31/2016") # works for Canada, fails for America
find("input[type='date']").set("2017-12-31") # works for America, fails for Canada

Is it possible to configure Capybara / Selenium to use a specific locale / formatting for inputs? Alternatively is it possible to determine the format of an input via JS and replace with a page.execute_script (setting to input.val(new Date(2016, 12, 31)) doesn't work)?

Kevin Sylvestre
  • 37,288
  • 33
  • 152
  • 232
  • Dates in javascript are such a mess that I've got used to using timestamps. Does this topic help? http://stackoverflow.com/questions/85116/display-date-time-in-users-locale-format-and-time-offset – Pyromonk Apr 25 '17 at 01:11

1 Answers1

1

The locale/formatting needed for inputs isn't set by Capybara/Selenium, it's set by the browser that's run (Capybara/Selenium don't actually know it's a date box they're filling in, they just send the keystrokes in the order you tell them). If you only have to deal with a few locales, one idea would be to use evaluate_script to get the value of navigator.language at the beginning of your specs and then change the format you send dates in based on that.

Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78