imacros - 未定义的路径

imacros - undefined path

我第一次玩 imacros,想做一个简单的脚本,在一个数组中有几个宏,然后 javascript 文件会随机 运行 其中一个每次都是宏。然而,出于某种原因,当我尝试 运行ning 时出现错误,指出我的路径未定义(错误代码 -991)。但是,我不知道为什么会收到此错误,因为我的路径是正确的。是否有一些我可能没有意识到的设置需要更改才能使我的简单虚拟脚本正常工作?

var options = new Array();
var i;
options.push("testAutomation/test1.iim");
options.push("testAutomation/test2.iim");
options.push("testAutomation/test3.iim");
options.push("testAutomation/test4.iim");
var randOption = options[Math.floor(Math.random() * options.length)];

for (i=0; i<4; i++){
iimPlay(options[randOption]);
}

这是因为您在此处获取实际值,但将其用作索引:

var randOption = options[Math.floor(Math.random() * options.length)];
// options["testAutomation/test1.iim"] => Undefined

randOption 在这种情况下将是实际的字符串值,因此例如 options["testAutomation/test1.iim"] 未定义,但 options[0] 是。

您想改用索引号,因此删除 options[...]

var randOption = Math.floor(Math.random() * options.length);
// options[0] => "testAutomation/test1.iim"