如何在一个iMacros脚本中使用多个循环进行锻炼?

时间:2016-07-07 18:00:55

标签: javascript imacros webautomation

我希望每个人都处于完美的健康状态。我正在尝试在我的iMacros脚本中添加两个for循环但只有第一个循环起作用然后停止脚本并且不会向前移动到第二个循环并结束出现以下错误:

  

TypeError:a未定义,第15行(错误代码:-991)

剧本:

var test;
test ="CODE:";
test +="SET !ERRORIGNORE YES "+" \n";
test +="TAB T=1"+" \n";
test +="URL GOTO=http://clicksandearns.com/index.php?tp=paidclicks "+" \n";

iimPlay(test);


var a_list = window.content.document.getElementsByTagName("a");

X = 1;
for (var i = 0, len = a_list.length; i <= len; i++) {
    var a = a_list[i];
    if (a.href.indexOf("tp=visit") > -1) {
var test;
test ="CODE:";
test +="SET !ERRORIGNORE YES "+" \n";
test +="' AD FIRST "+X+" \n";
test +="TAB OPEN "+" \n";
test +="TAB T=2"+" \n";
test +="URL GOTO="+a.href+" \n";
test +="WAIT SECONDS=13 "+" \n";
test +="FRAME NAME=visit "+" \n";
test +="TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:ss ATTR=TYPE:Submit&&NAME:submit&&VALUE:Continue<SP>for<SP>Credit "+" \n";
test +="WAIT SECONDS=2 "+" \n";
test +="TAB CLOSE"+" \n";


iimPlay(test);
X++;
    } 

    }

var test;
test ="CODE:";
test +="SET !ERRORIGNORE YES "+" \n";
test +="TAB T=1"+" \n";
test +="URL GOTO=http://clicksandearns.com/index.php?tp=paidclicks&st=&s=&start=35 "+" \n";

iimPlay(test);


var a_list = window.content.document.getElementsByTagName("a");

X = 1;
for (var i = 0, len = a_list.length; i <= len; i++) {
    var a = a_list[i];
    if (a.href.indexOf("tp=visit") > -1) {
var test;
test ="CODE:";
test +="SET !ERRORIGNORE YES "+" \n";
test +="' AD LAST "+X+" \n";
test +="TAB OPEN "+" \n";
test +="TAB T=2"+" \n";
test +="URL GOTO="+a.href+" \n";
test +="WAIT SECONDS=13 "+" \n";
test +="FRAME NAME=visit "+" \n";
test +="TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:ss ATTR=TYPE:Submit&&NAME:submit&&VALUE:Continue<SP>for<SP>Credit "+" \n";
test +="WAIT SECONDS=2 "+" \n";
test +="TAB CLOSE"+" \n";


iimPlay(test);
X++;
    } 

    }

期待是否有人可以帮助我解决这个问题,或者用这个问题来解决另一种替代方式。请感谢帮助..!

1 个答案:

答案 0 :(得分:1)

for循环中有错误:

for (var i = 0, len = a_list.length; i <= len; i++) {

应替换为:

for (var i = 0, len = a_list.length; i < len; i++) {

没有索引为len的项目 - 仅len-1 ... 因此,在尝试阅读href

undefined属性时会出现异常