user6103644
user6103644

Reputation:

How to Select today's date from a calender using Protractor

I'm writing a script in Protractor and I have a calendar in my angular application.

I used element(by.css('Today's date')).click(); to select today's date from the calender. But, I have to change the code everyday to select the today's date.

So, Is there a specific anyway to select the today's date from the calendar?

Thanks. :)

Upvotes: 0

Views: 2768

Answers (1)

TesterABC
TesterABC

Reputation: 1226

Use the following code.

 var pickerDue = element(by.model("supplier.enroll_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 = yyyy+'-'+mm+'-'+dd;

pickerDue.clear();
pickerDue.sendKeys(today);

For more information look at alecxe's answer here.

Hope this helps. :)

Upvotes: 1

Related Questions