Minimal example to reproduce:
The html page:
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<title>Date</title>
</head>
<body>
<input type="date" id="mydate"/>
</body>
</html>
The Java test code:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.testng.annotations.Test;
public class MinimalDateInputTest {
@Test
public void runTest() {
WebDriver driver = new HtmlUnitDriver();
driver.get("http://localhost:8000/date.html");
WebElement dateElement = driver.findElement(By.id("mydate"));
dateElement.sendKeys("2017-10-05");
System.out.println("dateElement.text: " + dateElement.getText());
driver.close();
}
}
The println does not print anything (aside from the static string). I would expect it to print the entered date.
Also, upon examining the source code of HtmlDateInput.java, I think it's less the ideal to just ignore a possible parsing exception:
@Override
public void setValueAttribute(final String newValue) {
try {
if (hasFeature(JS_INPUT_SET_VALUE_DATE_SUPPORTED)) {
FORMATTER_.parse(newValue);
}
super.setValueAttribute(newValue);
}
catch (final DateTimeParseException e) {
// ignore
}
}
I woudl expect a message to the user detailing the correct date format. However, the bug I'm reporting seems to be something else, since I'm entering the date in the correct format.
Thanks for the report. I already did some analysis on this some days before and already have an idea where to start fixing it. But i like to finalize my Promis rewrite task first. So please be a bit patiant.
I think I found the bug:
Its around line 555 in com.gargoylesoftware.htmlunit.html.HtmlElement. As you can see **HtlmDateInput ** is missing so the input event is never fired (confirmed this by debugging - the type at runtime is HtmlDateInput):
~~~
final WebClient webClient = page.getWebClient();
if (this instanceof HtmlTextInput
|| this instanceof HtmlTextArea
|| this instanceof HtmlTelInput
|| this instanceof HtmlNumberInput
|| this instanceof HtmlSearchInput
|| this instanceof HtmlPasswordInput) {
fireEvent(new KeyboardEvent(this, Event.TYPE_INPUT, c,
shiftPressed_ || isShiftNeeded, ctrlPressed_, altPressed_));
~~~
Last edit: Ralf Bommersbach 2019-03-05
The support for date fields is still not perfect but the value is no handled.