我一直在使用 SIDE 来自动化工作中的一些流程。我使用 store 命令从页面收集一些日期,并尝试使用执行脚本命令来计算持续时间,然后将其输入页面上的其他位置。目前,我通过 echo 命令得到 NaN 作为我的脚本的结果,并看到它在持续时间应该去的框中写入 NaN。
我通过执行脚本函数传递的脚本是这样的:
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}`;
我使用 echo 来检查所有输入(月底等),它们返回了预期结果。 我使用 echo 来检查 scriptcito,它返回 NaN。
我尝试过使用 ChatGPT 的建议,但它似乎不明白我自己没有创建 python 代码,而是让我将东西输入到 Selenium 中,这会破坏那台机器。
如何将内容传递到浏览器的示例:
value = driver.execute_script('''
let [startMonth, startYear, endMonth, endYear] = arguments
//... code goes here
return something
''', startMonth, startYear, endMonth, endYear)