Monday, December 27, 2010

Get current system date using java script in Selenium IDE

Hello Everyone,

In this blog the user will generate current system date using javascript as

Store ||  javascript{ ((new Date()).getMonth()+1)+'/'+(new Date()).getDate()+'/'+(new Date()).getFullYear()}  ||  Variable_name

 will generate the date as MM/DD/YYYY format

you can check it using following code of selenium

echo || ${Variable_name}  ||

Following is the screen shot of how to implement the above code

I hope this will help you in automation

If any query please mail it to


  1. Thanks. Do you have the JS to display date in with laeding zero for single digit date/month, like 06/08/2011

    1. This comment has been removed by the author.

  2. Use this

    javascript{var currentDate = new Date();var day = currentDate.getDate(); if (day < 10) { day = "0" + day }; var month = currentDate.getMonth() + 1; if (month < 10) { month = "0" + month };var year = currentDate.getFullYear(); curentDate=(day + "/" + month + "/" + year);}


  3. How would this JS be formatted in Selenium IDE?

  4. Hi,
    I'm a beginner in Selenium and I needed to verify current Date in a different format
    e.g. Thursday September 10, 2015
    So I modified the code mentioned above just a little bit
    javascript{(new Date()).getDay())+' '+((new Date()).getMonth()+1)+' '+(new Date()).getDate()+', '+(new Date()).getFullYear()}

    But, it threw an error
    [error] Unexpected Exception: SyntaxError: missing ; before statement.

    Can you please find out what is wrong in this code? I didn't see any semicolon in code mentioned above, so don't even know where to put one.
    Also, this would definitely not get me Day and Month name. Can you help?