Skip to content

Commit c52f587

Browse files
Support <input type="datetime-local">
1 parent 434ff84 commit c52f587

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/org/labkey/test/WebDriverWrapper.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3709,6 +3709,9 @@ private void setHtml5Input(WebElement input, String inputType, String value)
37093709
case "date":
37103710
setHtml5DateInput(input, value);
37113711
break;
3712+
case "datetime-local":
3713+
setHtml5DateTimeInput(input, value);
3714+
break;
37123715
case "password":
37133716
case "search":
37143717
setInput(input, value); // These don't require special handling, don't output warning
@@ -3737,6 +3740,21 @@ private void setHtml5DateInput(WebElement el, String text)
37373740
}
37383741
}
37393742

3743+
private void setHtml5DateTimeInput(WebElement el, String text)
3744+
{
3745+
String inputFormat = "yyyy-MM-dd'T'HH:mm";
3746+
SimpleDateFormat inputFormatter = new SimpleDateFormat(inputFormat);
3747+
3748+
try
3749+
{
3750+
setHtml5DateTimeInput(el, inputFormatter.parse(text));
3751+
}
3752+
catch (ParseException e)
3753+
{
3754+
throw new IllegalArgumentException("Unable to parse date " + text + ". Format should be " + inputFormat);
3755+
}
3756+
}
3757+
37403758
private void setHtml5DateInput(WebElement el, Date date)
37413759
{
37423760
// Firefox requires ISO date format (yyyy-MM-dd)
@@ -3749,6 +3767,18 @@ private void setHtml5DateInput(WebElement el, Date date)
37493767
el.sendKeys(formDate);
37503768
}
37513769

3770+
private void setHtml5DateTimeInput(WebElement el, Date date)
3771+
{
3772+
// Firefox and Chrome want different formats, neither of which align with all online guidance to use ISO-style
3773+
String formFormat = isFirefox() ? "MMddyyyy hh:mm a" : "MM-dd-yyyy'\t'hh:mma";
3774+
SimpleDateFormat formFormatter = new SimpleDateFormat(formFormat);
3775+
String formDate = formFormatter.format(date);
3776+
3777+
fireEvent(el, SeleniumEvent.focus);
3778+
executeScript("arguments[0].value = ''", el);
3779+
el.sendKeys(formDate);
3780+
}
3781+
37523782
private void setHtml5NumberInput(WebElement el, String text)
37533783
{
37543784

0 commit comments

Comments
 (0)