How to test a Angular js date picker from Protractor

I think you can avoid manipulating the datepicker manually and instead set the date either by just sending the keys with a today’s date value:

var picker = element(by.model("invoice.fromdate"));

// get today's date
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();

if(dd<10) {
    dd='0'+dd
} 

if(mm<10) {
    mm='0'+mm
} 

today = mm+"https://stackoverflow.com/"+dd+"https://stackoverflow.com/"+yyyy;

picker.clear();
picker.sendKeys(today);

Or, by setting the associated model’s value directly:

picker.evaluate("invoice.fromdate="" + today + """);

Leave a Comment