[HtmlUnit] [htmlunit:bugs] #1923 input element with type date does not store a value

RBRi via HtmlUnit-develop <[email protected]> Thu, 07 Mar 2019 19:42:37 -0000
Newsgroups gmane.comp.java.htmlunit.devel
Message-ID </p/htmlunit/bugs/1923/68536246f36830a7318e3540533c30e37a1871ad.bugs@htmlunit.p.sourceforge.net>
This is a multi-part message in MIME format.
--===============3580922063606410143==
Content-Type: multipart/related;
 boundary="===============2380253339408148058=="

This is a multi-part message in MIME format.
--===============2380253339408148058==
Content-Type: multipart/alternative;
 boundary="===============5620592287901617117=="
MIME-Version: 1.0

--===============5620592287901617117==
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit

- **status**: accepted --> closed
- **assigned_to**: RBRi
- **Comment**:

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



---

** [bugs:#1923] input element with type date does not store a value**

**Status:** closed
**Group:** 2.27
**Labels:** input date 
**Created:** Thu Oct 05, 2017 12:09 PM UTC by MickeyKnox
**Last Updated:** Tue Mar 05, 2019 02:10 PM UTC
**Owner:** RBRi


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.


---

Sent from sourceforge.net because [email protected] is subscribed to https://sourceforge.net/p/htmlunit/bugs/

To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/htmlunit/admin/bugs/options.  Or, if this is a mailing list, you can unsubscribe from the mailing list.
--===============5620592287901617117==
MIME-Version: 1.0
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: 7bit

<div class="markdown_content"><ul>
<li><strong>status</strong>: accepted --&gt; closed</li>
<li><strong>assigned_to</strong>: RBRi</li>
<li><strong>Comment</strong>:</li>
</ul>
<p>The support for date fields is still not perfect but the value is no handled.</p>
<hr/>
<p><strong> <a class="alink strikethrough" href="https://sourceforge.net/p/htmlunit/bugs/1923/">[bugs:#1923]</a> input element with type date does not store a value</strong></p>
<p><strong>Status:</strong> closed<br/>
<strong>Group:</strong> 2.27<br/>
<strong>Labels:</strong> input date <br/>
<strong>Created:</strong> Thu Oct 05, 2017 12:09 PM UTC by MickeyKnox<br/>
<strong>Last Updated:</strong> Tue Mar 05, 2019 02:10 PM UTC<br/>
<strong>Owner:</strong> RBRi</p>
<p>Minimal example to reproduce:</p>
<p>The html page: </p>
<div class="codehilite"><pre><span></span><span class="cp">&lt;!DOCTYPE html&gt;</span>
<span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">head</span><span class="p">&gt;</span>
      <span class="p">&lt;</span><span class="nt">meta</span> <span class="na">content</span><span class="o">=</span><span class="s">"text/html;charset=utf-8"</span> <span class="na">http-equiv</span><span class="o">=</span><span class="s">"Content-Type"</span><span class="p">&gt;</span>
      <span class="p">&lt;</span><span class="nt">meta</span> <span class="na">content</span><span class="o">=</span><span class="s">"utf-8"</span> <span class="na">http-equiv</span><span class="o">=</span><span class="s">"encoding"</span><span class="p">&gt;</span>
        <span class="p">&lt;</span><span class="nt">title</span><span class="p">&gt;</span>Date<span class="p">&lt;/</span><span class="nt">title</span><span class="p">&gt;</span>
    <span class="p">&lt;/</span><span class="nt">head</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>
      <span class="p">&lt;</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">"date"</span> <span class="na">id</span><span class="o">=</span><span class="s">"mydate"</span><span class="p">/&gt;</span>
    <span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
<span class="p">&lt;/</span><span class="nt">html</span><span class="p">&gt;</span>
</pre></div>


<p>The Java test code:</p>
<div class="codehilite"><pre><span></span><span class="kn">import</span> <span class="nn">org.openqa.selenium.By</span><span class="p">;</span>
<span class="kn">import</span> <span class="nn">org.openqa.selenium.WebDriver</span><span class="p">;</span>
<span class="kn">import</span> <span class="nn">org.openqa.selenium.WebElement</span><span class="p">;</span>
<span class="kn">import</span> <span class="nn">org.openqa.selenium.htmlunit.HtmlUnitDriver</span><span class="p">;</span>
<span class="kn">import</span> <span class="nn">org.testng.annotations.Test</span><span class="p">;</span>

<span class="n">public</span> <span class="k">class</span> <span class="nc">MinimalDateInputTest</span> <span class="p">{</span>

  <span class="nd">@Test</span>
  <span class="n">public</span> <span class="n">void</span> <span class="n">runTest</span><span class="p">()</span> <span class="p">{</span>
    <span class="n">WebDriver</span> <span class="n">driver</span> <span class="o">=</span> <span class="n">new</span> <span class="n">HtmlUnitDriver</span><span class="p">();</span>
    <span class="n">driver</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">"http://localhost:8000/date.html"</span><span class="p">);</span>
    <span class="n">WebElement</span> <span class="n">dateElement</span> <span class="o">=</span> <span class="n">driver</span><span class="o">.</span><span class="n">findElement</span><span class="p">(</span><span class="n">By</span><span class="o">.</span><span class="n">id</span><span class="p">(</span><span class="s2">"mydate"</span><span class="p">));</span>
    <span class="n">dateElement</span><span class="o">.</span><span class="n">sendKeys</span><span class="p">(</span><span class="s2">"2017-10-05"</span><span class="p">);</span>
    <span class="n">System</span><span class="o">.</span><span class="n">out</span><span class="o">.</span><span class="n">println</span><span class="p">(</span><span class="s2">"dateElement.text: "</span> <span class="o">+</span> <span class="n">dateElement</span><span class="o">.</span><span class="n">getText</span><span class="p">());</span>
    <span class="n">driver</span><span class="o">.</span><span class="n">close</span><span class="p">();</span>
  <span class="p">}</span>
<span class="p">}</span>
</pre></div>


<p>The println does not print anything (aside from the static string). I would expect it to print the entered date.</p>
<p>Also, upon examining the source code of HtmlDateInput.java, I think it's less the ideal to just ignore a possible parsing exception:</p>
<div class="codehilite"><pre><span></span>    @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
        }
    }
</pre></div>


<p>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.</p>
<hr/>
<p>Sent from sourceforge.net because [email protected] is subscribed to <a href="https://sourceforge.net/p/htmlunit/bugs/">https://sourceforge.net/p/htmlunit/bugs/</a></p>
<p>To unsubscribe from further messages, a project admin can change settings at <a href="https://sourceforge.net/p/htmlunit/admin/bugs/options.">https://sourceforge.net/p/htmlunit/admin/bugs/options.</a>  Or, if this is a mailing list, you can unsubscribe from the mailing list.</p></div>
--===============5620592287901617117==--
--===============2380253339408148058==--


--===============3580922063606410143==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


--===============3580922063606410143==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
HtmlUnit-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/htmlunit-develop

--===============3580922063606410143==--