3
votes

I'm trying to get the current date and time in Selenium IDE (latest version 3.7.4) in a format like this 2019-05-21 12:35:23 that is YYYY-MM-DD hh:mm:ss

I'm new to javascript and what I found so far is that in Javascript the current date is obtained from system using new Date();

So I've set the following commands in Selenium IDE

1)
Command: execute script
Target: new Date();
Value: currentdate

2)
Command: echo
Target: $(currentdate)
Value:

But it seems Date(); is not working and is not stored in variable currentdate. This is the output

executeScript on new Date(); with value currentdate OK
echo: undefined
'Untitled' completed successfully

What I'm doing wrong? Thanks for help in advance.

1

1 Answers

0
votes

I stumbled across your question while looking for a way to do this myself. I found the answer elsewhere, so I thought I'd share it here in hopes of helping others.

You need to begin your JavaScript line with "return", like this:

return new Date();

This should place a verbose Date() value in your currentDate variable, which you can echo or use elsewhere. You'll probably want to format it using the toLocaleString() method, though, like this:

return new Date().toLocaleString();

That should return the date/time more closely formatted to your needs.