Menu

#1923 input element with type date does not store a value

2.27
closed
RBRi
1
2019-03-07
2017-10-05
MickeyKnox
No

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.

Discussion

  • RBRi

    RBRi - 2017-10-06

    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.

     
  • RBRi

    RBRi - 2017-10-06
    • status: open --> accepted
     
  • Ralf Bommersbach

    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
  • RBRi

    RBRi - 2019-03-07
    • status: accepted --> closed
    • assigned_to: RBRi
     
  • RBRi

    RBRi - 2019-03-07

    The support for date fields is still not perfect but the value is no handled.

     

Log in to post a comment.