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 Akshah2688@gmail.com
Thanks. Do you have the JS to display date in with laeding zero for single digit date/month, like 06/08/2011
ReplyDeleteThis comment has been removed by the author.
DeleteUse this
ReplyDeletejavascript{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);}
Regards
Arun.venkat.t@gmail.com
How would this JS be formatted in Selenium IDE?
ReplyDeleteHi,
ReplyDeleteI'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?