Selenium IDE: How do I get today's date?

前端 未结 5 700
情歌与酒
情歌与酒 2021-02-05 22:16

I\'m testing my web application using Selenium IDE. There are test cases in which I have to assert that today\'s date appears on the page. I cannot hard code today\'s date in th

5条回答
  •  感情败类
    2021-02-05 23:17

    The line var d=new Date(); d.getDate()+'-'+((d.getMonth()+1))+'-'+d.getFullYear(); works but returns the month as single-digit.

    For my test case, I need the date returned in the format YYYY-MM-DD, so I use

    var d= new Date(); var m=((d.getMonth()+1)<10)?'0'+(d.getMonth()+1):(d.getMonth()+1); d.getFullYear()+"-"+m+"-"+d.getDate();
    

提交回复
热议问题