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
Try this in Selenium IDE. It will print the timestamp as yyyymmddhhmmss.
<tr>
<td>storeExpression</td>
<td>javascript{var date = new Date();date.getFullYear() + '' + ((date.getMonth()+1<10)?('0'+(date.getMonth()+1)):(date.getMonth()+1)) + '' + ((date.getDate()+1<10)?('0'+(date.getDate()+1)):(date.getDate()+1)) + '' + date.getHours() + '' + date.getMinutes() + '' + date.getSeconds();}</td>
<td>date</td>
</tr>
<tr>
<td>echo</td>
<td>${date}</td>
<td></td>
</tr>
Not sure what format your date is in, but you could do something like this:
<tr>
<td>storeEval</td>
<td>var d=new Date(); d.getDate()+'-'+((d.getMonth()+1))
+'-'+d.getFullYear();</td>
<td>date2</td>
</tr>
<tr>
<td>echo</td>
<td>${date2}</td>
<td></td>
</tr>
Double-digits for M and D (i.e. MM/DD/YYYY format):
<td>var t= new Date(); var d=((t.getDate())<10)?'0'+(t.getDate()):(t.getDate()); var m=((t.getMonth()+1)<10)?'0'+(t.getMonth()+1):(t.getMonth()+1); m+"/"+d+"/"+t.getFullYear();</td>
I am a bit confused about the answers here. From my side, what I wanted to do is to include the current date in an input text-area.
Here is how I did it:
The line
<td>var d=new Date(); d.getDate()+'-'+((d.getMonth()+1))+'-'+d.getFullYear();</td>
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
<td>var d= new Date(); var m=((d.getMonth()+1)<10)?'0'+(d.getMonth()+1):(d.getMonth()+1); d.getFullYear()+"-"+m+"-"+d.getDate();</td>