How do I properly setValue on a Date field?

319 views
Skip to first unread message

Nathan Sutherland

unread,
Sep 19, 2016, 12:02:59 PM9/19/16
to NightwatchJs
I posted this on the github issue tracker, where it was suggested I ask over here.

Issue: When I use .setValue() on an input of type="date", the next time I call .value() on the input, the date is way off.

Example test:


'Setting Date Field' : function(browser)  {

    browser.url('http://adam.goucher.ca/parkcalc/');    // fun website to test

    var targetDate = '2016-11-12';

    // Create date field
    browser.execute( 
        function() {
            var elemDiv = document.createElement('input');
            elemDiv.id="onlyDate";
            elemDiv.type="Date";
            document.body.appendChild(elemDiv);
        }
    ).pause(300);   // pause rather than using a callback

    browser.setValue('#onlyDate',targetDate);

    browser.expect.element('#onlyDate').to.have.value.which.is.equal(targetDate);

    browser.end();

},
Result:
Expected element <#onlyDate> to have value which equals "2016-11-12" - expected "equals '2016-11-12'" but got: "61112-02-01".

From what I can tell, this is because the DATE input in chrome looks like this: mm-dd-yyyy (by default), and when .setValue() sends the keypresses for "2016-11-12", the focus starts on the mm part and proceeds "automatically" from there. Obviously typing in the exact kepyresses of 2016-11-12 will not set the value properly.

So is this a bug? I've looked at some of the http://nightwatchjs.org/api#elementIdValue and simular pages, it looks like selenium just assumes that sending keystrokes to an input element will set it's value.

How do others set the value of input=date and input=time fields?
Reply all
Reply to author
Forward
0 new messages