I hope that everyone will be in perfect health.I am trying to add two for loops in my iMacros script but only the first loop works and then stops the script and doesn't move forward to the 2nd loop and ends with the following error as :
TypeError: a is undefined, line 15 (Error code: -991)
The Script :
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++;
}
}
Looking forward if anyone can help me out with this issue or to workout with this issue some another alternate way.Will be grateful for the help..!
There is an error in your for loops:
for (var i = 0, len = a_list.length; i <= len; i++) {
It should be replaced with:
for (var i = 0, len = a_list.length; i < len; i++) {
There is no items with index len
- only len-1
...
As a result you get an exception when trying to read href
property of undefined