For work automation, I've been utilizing SIDE to streamline certain tasks. One challenge I'm facing involves extracting dates from a page using the store command and then attempting to calculate a duration using the execute script command, which should then be input in another section of the page. However, my current issue is that when running the script, the result shows NaN (Not a Number) instead of the calculated duration, leading to it being displayed as NaN in the designated box on the page.
In my Selenium IDE window, here's how things appear: Image showing stored variables and script
The script used with the execute script function is as follows:
const startDate = new Date(`${StartYear}`, `${StartMonth}` - 1, 1);
const endDate = new Date(`${EndYear}`, `${EndMonth}`, 1);
const durationInMilliseconds = endDate.getTime() - startDate.getTime();
const durationInYears = durationInMilliseconds / (1000 * 60 * 60 * 24 * 365.25);
const roundedDuration = Math.round(durationInYears * 2) / 2;
return `${roundedDuration}`;
After checking all inputs through echo (such as endmonth), they return the expected values. Using echo to verify scriptcito, however, results in NaN being displayed.
Despite seeking guidance from ChatGPT, the advice given assumes I am coding in Python myself rather than dealing directly with Selenium commands, causing issues with the process.