Help with Imacros with javascript.

Discussions and Tech Support specific to the iMacros Firefox add-on.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
pinga123
Posts: 20
Joined: Thu May 19, 2016 7:43 am

Help with Imacros with javascript.

Post by pinga123 » Thu May 19, 2016 4:26 pm

I m trying to execute an imacro embedded in javascript . the code executes however after first 3-4 attempts it gives me an error saying

Code: Select all

Runtimeerror: Tab number 4 does not exists line 5
Here is the working of the code the file contains a list of urls to be visited.
code take the entries and go to respective url. with below code i can only visit first 2-3 url after it gives me the above error . Not sure what is wrong in the code.
Code :

Code: Select all

var macro;
var retcode, errtext;



for (i=1 ;i <=100 ;i++) {
iimSet("i",i);
macro = "CODE:";
macro += "Tab open \n"
macro += "SET !DATASOURCE groupurl.txt\n";
macro += "SET !DATASOURCE_COLUMNS 2\n";
macro +=  "SET !DATASOURCE_LINE {{i}}" + "\n";
macro += "TAB T={{i}}\n";
macro += "URL GOTO={{!COL1}}";
retcode = iimPlay(macro);

if (retcode < 0) {              
    errtext = iimGetLastError();
    alert(errtext);
}
}
Please help .
chivracq
Posts: 9715
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Help with Imacros with javascript.

Post by chivracq » Thu May 19, 2016 5:07 pm

pinga123 wrote:I m trying to execute an imacro embedded in javascript . the code executes however after first 3-4 attempts it gives me an error saying

Code: Select all

Runtimeerror: Tab number 4 does not exists line 5
Here is the working of the code the file contains a list of urls to be visited.
code take the entries and go to respective url. with below code i can only visit first 2-3 url after it gives me the above error . Not sure what is wrong in the code.
Code :

Code: Select all

var macro;
var retcode, errtext;

for (i=1 ;i <=100 ;i++) {
iimSet("i",i);
macro = "CODE:";
macro += "Tab open \n"
macro += "SET !DATASOURCE groupurl.txt\n";
macro += "SET !DATASOURCE_COLUMNS 2\n";
macro +=  "SET !DATASOURCE_LINE {{i}}" + "\n";
macro += "TAB T={{i}}\n";
macro += "URL GOTO={{!COL1}}";
retcode = iimPlay(macro);

if (retcode < 0) {              
    errtext = iimGetLastError();
    alert(errtext);
}
}
Please help .
Thread Title is not very Descriptive/Specific to your Pb, nearly all Threads on this Sub-Forum are related to Pb's/Qt's about "iMacros + JavaScript"... :roll:

FCIM...! :mrgreen: (Always mention your FCI when you open a Thread, read my Sig, many Commands are not implemented for all Browsers/Versions...)
=> iMacros for FF v...?, FF v...?, OS...?

Yep, concerning your Pb, I think you forgot to tell your Macro to go back to 'TAB=1', or you keep your Script like it is and you tell iMacros to go to 'TAB=2' at each Loop instead of 'TAB=i'...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
pinga123
Posts: 20
Joined: Thu May 19, 2016 7:43 am

Re: Help with Imacros with javascript.

Post by pinga123 » Fri May 20, 2016 8:11 am

chivracq wrote:
pinga123 wrote:I m trying to execute an imacro embedded in javascript . the code executes however after first 3-4 attempts it gives me an error saying

Code: Select all

Runtimeerror: Tab number 4 does not exists line 5
Here is the working of the code the file contains a list of urls to be visited.
code take the entries and go to respective url. with below code i can only visit first 2-3 url after it gives me the above error . Not sure what is wrong in the code.
Code :

Code: Select all

var macro;
var retcode, errtext;

for (i=1 ;i <=100 ;i++) {
iimSet("i",i);
macro = "CODE:";
macro += "Tab open \n"
macro += "SET !DATASOURCE groupurl.txt\n";
macro += "SET !DATASOURCE_COLUMNS 2\n";
macro +=  "SET !DATASOURCE_LINE {{i}}" + "\n";
macro += "TAB T={{i}}\n";
macro += "URL GOTO={{!COL1}}";
retcode = iimPlay(macro);

if (retcode < 0) {              
    errtext = iimGetLastError();
    alert(errtext);
}
}
Please help .
Thread Title is not very Descriptive/Specific to your Pb, nearly all Threads on this Sub-Forum are related to Pb's/Qt's about "iMacros + JavaScript"... :roll:

FCIM...! :mrgreen: (Always mention your FCI when you open a Thread, read my Sig, many Commands are not implemented for all Browsers/Versions...)
=> iMacros for FF v...?, FF v...?, OS...?

Yep, concerning your Pb, I think you forgot to tell your Macro to go back to 'TAB=1', or you keep your Script like it is and you tell iMacros to go to 'TAB=2' at each Loop instead of 'TAB=i'...
Thanks you very much for quick reply :) good to be part of community which actually care about new members. Yes i missed few stuff (probably because its my first post here )
here is the details

Code: Select all

 firefox version : 46.0.1 
Using windows 7 professional service pack 1 64 bit 
Imacros version : BUILD=8970419
IF i try changing tab=1 it will only open url in one tab and then the next url will also be opened in the same tab . However i want the script to open url on different tab.
When i change TAB T={{i}} i get into an error of tab number does not exists after initial few runs.
along with this i have trouble converting other iim code to .js file .
My main reason for creating the js file is to implement if else condition . If certain tags are not found or commands are not executed then another set of code should be executed.
My iim code works perfectly for this however conversion to js is what i m finding difficult .
even i tried including below line in js . however it says invalide url format. The same code works perfectly in iim.

Code: Select all

macro += "TAG POS=1 TYPE=TEXTAREA FORM=ACTION:/composer/mbasic/?av=888888888888&refid=18 ATTR=ID:u_* CONTENT=Gift"
Please suggest.
chivracq
Posts: 9715
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Help with Imacros with javascript.

Post by chivracq » Fri May 20, 2016 2:21 pm

pinga123 wrote:Thanks you very much for quick reply :) good to be part of community which actually care about new members. Yes i missed few stuff (probably because its my first post here )
here is the details

Code: Select all

 firefox version : 46.0.1 
Using windows 7 professional service pack 1 64 bit 
Imacros version : BUILD=8970419
IF i try changing tab=1 it will only open url in one tab and then the next url will also be opened in the same tab . However i want the script to open url on different tab.
When i change TAB T={{i}} i get into an error of tab number does not exists after initial few runs.
along with this i have trouble converting other iim code to .js file .
My main reason for creating the js file is to implement if else condition . If certain tags are not found or commands are not executed then another set of code should be executed.
My iim code works perfectly for this however conversion to js is what i m finding difficult .
even i tried including below line in js . however it says invalide url format. The same code works perfectly in iim.

Code: Select all

macro += "TAG POS=1 TYPE=TEXTAREA FORM=ACTION:/composer/mbasic/?av=888888888888&refid=18 ATTR=ID:u_* CONTENT=Gift"
Please suggest.
OK, good for FCI...

I didn't mean "changing tab=1" but adding going back to TAB_1 at the end of your Macro, because at the next Loop, iMacros always thinks that the TAB it is starting the Macro from is TAB_1 but what your Script is doing is that it starts from TAB_1, opens a TAB (=TAB_2), goes to TAB_2, end of Loop_1, so far so good..., Loop_2, starts from TAB_2, opens a TAB (=TAB_3), goes to TAB_4 (should go to TAB_3...!), if TAB_4 existed then OK, end of Loop_2, Loop_3, starts from TAB_4, opens a TAB (=TAB_5), goes to TAB_7 (should go to TAB_4...!), and here or at the next Loop (which will try to go to TAB_11...!) it goes wrong because you didn't have so many TAB's open when you started running your Script.

And I'm not even sure that going back to TAB_1 at the end of a Loop will work properly at the next Loop, because the Browser decides a bit where it opens a New TAB, either directly on the Right to your Current TAB, or on the Right after the Last TAB of Grouped TAB's, or completely on the Right as the very Last TAB, and going to TAB_i will maybe not go to the TAB your expect...
So a better Approach I think would be the 2nd one I mentioned in my previous Reply, i.e. to always go to TAB_2 which is always the (relative) TAB you just opened, and for each new Loop, the TAB you just opened in the previous Loop becomes TAB_1.

For Conditional Behaviour, you may want to have a look at the following Thread where I explained a few Techniques I use to achieve (from Basic till very Complex Conditional Logic) using pure '.iim' Macros. I don't use one single '.js' Script and I achieve very Complex "Things" in pure '.iim' that can qualify for AI using those Techniques, where my Macros decide if/when/which one(s)/how many times to loop/etc... by themselves to run, and are even able to automorph and modify themselves if needed and/or to alert me if needed or if anything goes wrong...:
- Workarounds for Conditional Logic in Macro Code

And yep, converting '.iim' Macros to on the fly generated Macros for in a '.js' Script is always a bit of a hassle, you need to think to escape all Double Quotes and Backward Slashes (like in Paths for example) and any other "Special" Characters.
If you install iMacros for IE, you have a Tool in the iMacros Editor to convert Macros with one Click and there is another (Online...?) Tool developed a few years ago referred to from the Wiki or the Forum to do the same...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
pinga123
Posts: 20
Joined: Thu May 19, 2016 7:43 am

Re: Help with Imacros with javascript.

Post by pinga123 » Thu May 26, 2016 9:42 am

chivracq wrote:
pinga123 wrote:Thanks you very much for quick reply :) good to be part of community which actually care about new members. Yes i missed few stuff (probably because its my first post here )
here is the details

Code: Select all

 firefox version : 46.0.1 
Using windows 7 professional service pack 1 64 bit 
Imacros version : BUILD=8970419
IF i try changing tab=1 it will only open url in one tab and then the next url will also be opened in the same tab . However i want the script to open url on different tab.
When i change TAB T={{i}} i get into an error of tab number does not exists after initial few runs.
along with this i have trouble converting other iim code to .js file .
My main reason for creating the js file is to implement if else condition . If certain tags are not found or commands are not executed then another set of code should be executed.
My iim code works perfectly for this however conversion to js is what i m finding difficult .
even i tried including below line in js . however it says invalide url format. The same code works perfectly in iim.

Code: Select all

macro += "TAG POS=1 TYPE=TEXTAREA FORM=ACTION:/composer/mbasic/?av=888888888888&refid=18 ATTR=ID:u_* CONTENT=Gift"
Please suggest.
OK, good for FCI...

I didn't mean "changing tab=1" but adding going back to TAB_1 at the end of your Macro, because at the next Loop, iMacros always thinks that the TAB it is starting the Macro from is TAB_1 but what your Script is doing is that it starts from TAB_1, opens a TAB (=TAB_2), goes to TAB_2, end of Loop_1, so far so good..., Loop_2, starts from TAB_2, opens a TAB (=TAB_3), goes to TAB_4 (should go to TAB_3...!), if TAB_4 existed then OK, end of Loop_2, Loop_3, starts from TAB_4, opens a TAB (=TAB_5), goes to TAB_7 (should go to TAB_4...!), and here or at the next Loop (which will try to go to TAB_11...!) it goes wrong because you didn't have so many TAB's open when you started running your Script.

And I'm not even sure that going back to TAB_1 at the end of a Loop will work properly at the next Loop, because the Browser decides a bit where it opens a New TAB, either directly on the Right to your Current TAB, or on the Right after the Last TAB of Grouped TAB's, or completely on the Right as the very Last TAB, and going to TAB_i will maybe not go to the TAB your expect...
So a better Approach I think would be the 2nd one I mentioned in my previous Reply, i.e. to always go to TAB_2 which is always the (relative) TAB you just opened, and for each new Loop, the TAB you just opened in the previous Loop becomes TAB_1.

For Conditional Behaviour, you may want to have a look at the following Thread where I explained a few Techniques I use to achieve (from Basic till very Complex Conditional Logic) using pure '.iim' Macros. I don't use one single '.js' Script and I achieve very Complex "Things" in pure '.iim' that can qualify for AI using those Techniques, where my Macros decide if/when/which one(s)/how many times to loop/etc... by themselves to run, and are even able to automorph and modify themselves if needed and/or to alert me if needed or if anything goes wrong...:
- Workarounds for Conditional Logic in Macro Code

And yep, converting '.iim' Macros to on the fly generated Macros for in a '.js' Script is always a bit of a hassle, you need to think to escape all Double Quotes and Backward Slashes (like in Paths for example) and any other "Special" Characters.
If you install iMacros for IE, you have a Tool in the iMacros Editor to convert Macros with one Click and there is another (Online...?) Tool developed a few years ago referred to from the Wiki or the Forum to do the same...
Thank you very much your solution worked out .
I changed tab=2 and now the problem is solved. I tried calling .iim from js code however it used to destroy all variable values so i had to convert everything into js code only.
I m trying to save the url of links i have visited those who didnt able to meet the criteria specified by my script . Now sure how do i accomplish it in js code. :(
Here is the scriptlet i m using request you to have a look

Code: Select all

retcode2=iimPlay(macro3)
if (retcode2 < 0) {  
iimDisplay("Error Found:");
macro4 += "CODE:";
macro4 += "ADD !EXTRACT {{!URLCURRENT}}" + "\n"; 
macro4 += "SAVEAS TYPE=EXTRACT FOLDER=* FILE=ErrorLinks.csv\n";

iimPlay(macro4);
}
Not sure where will be the file created. I m able to see the Error found prompt which means its getting executed but there seems to be no error and no file created.
chivracq
Posts: 9715
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Help with Imacros with javascript.

Post by chivracq » Thu May 26, 2016 9:01 pm

pinga123 wrote:Thank you very much your solution worked out .
I changed tab=2 and now the problem is solved. I tried calling .iim from js code however it used to destroy all variable values so i had to convert everything into js code only.
I m trying to save the url of links i have visited those who didnt able to meet the criteria specified by my script . Now sure how do i accomplish it in js code. :(
Here is the scriptlet i m using request you to have a look

Code: Select all

retcode2=iimPlay(macro3)
if (retcode2 < 0) {  
iimDisplay("Error Found:");
macro4 += "CODE:";
macro4 += "ADD !EXTRACT {{!URLCURRENT}}" + "\n"; 
macro4 += "SAVEAS TYPE=EXTRACT FOLDER=* FILE=ErrorLinks.csv\n";

iimPlay(macro4);
}
Not sure where will be the file created. I m able to see the Error found prompt which means its getting executed but there seems to be no error and no file created.
OK, glad to hear that the 'TAB T=2' Suggestion worked indeed...

For the rest, pfff..., I don't really know, I'm no JavaScript Guru, that's why I prefer to use pure '.iim'..., your Script looks fine to me, I would think...

Suggestions/Remarks:
1- The 'SAVEAS' File is created in your Default 'Downloads' Folder set in the iMacros Options.

2- Check the Value of 'retcode2', I think there was a Bug about the RetCodes in some recent Version of iMacros for FF, v8.9.6 or it could be for this current v8.9.7 Version...

3- Display as well the ErrorMsg with 'iimGetLastError()'.

4- Try putting the on the fly Macro Declaration for 'macro4' outside the Function.

5- Add a 'PROMPT' and/or copying stg specific to the Clipboard in 'macro4' to make sure it is run.
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
pinga123
Posts: 20
Joined: Thu May 19, 2016 7:43 am

Re: Help with Imacros with javascript.

Post by pinga123 » Sat May 28, 2016 3:29 pm

chivracq wrote:
pinga123 wrote:Thank you very much your solution worked out .
I changed tab=2 and now the problem is solved. I tried calling .iim from js code however it used to destroy all variable values so i had to convert everything into js code only.
I m trying to save the url of links i have visited those who didnt able to meet the criteria specified by my script . Now sure how do i accomplish it in js code. :(
Here is the scriptlet i m using request you to have a look

Code: Select all

retcode2=iimPlay(macro3)
if (retcode2 < 0) {  
iimDisplay("Error Found:");
macro4 += "CODE:";
macro4 += "ADD !EXTRACT {{!URLCURRENT}}" + "\n"; 
macro4 += "SAVEAS TYPE=EXTRACT FOLDER=* FILE=ErrorLinks.csv\n";

iimPlay(macro4);
}
Not sure where will be the file created. I m able to see the Error found prompt which means its getting executed but there seems to be no error and no file created.
OK, glad to hear that the 'TAB T=2' Suggestion worked indeed...

For the rest, pfff..., I don't really know, I'm no JavaScript Guru, that's why I prefer to use pure '.iim'..., your Script looks fine to me, I would think...

Suggestions/Remarks:
1- The 'SAVEAS' File is created in your Default 'Downloads' Folder set in the iMacros Options.

2- Check the Value of 'retcode2', I think there was a Bug about the RetCodes in some recent Version of iMacros for FF, v8.9.6 or it could be for this current v8.9.7 Version...

3- Display as well the ErrorMsg with 'iimGetLastError()'.

4- Try putting the on the fly Macro Declaration for 'macro4' outside the Function.

5- Add a 'PROMPT' and/or copying stg specific to the Clipboard in 'macro4' to make sure it is run.
thanks for your prompt reply to the queries . I have modified the script as per your suggestion . macro4 was defined outside only.
My initial 4 lines of code

Code: Select all

var macro;
var macro2;
var macro3;
var macro4;
heres how i modified earlier version of code

Code: Select all

if (retcode2 < 0) {  
iimDisplay("Error Found:"+Errorstring+"retcode:"+retcode2);
macro4 += "CODE:";
macro4 += "ADD !EXTRACT {{!URLCURRENT}}" + "\n"; 
macro4 += "SAVEAS TYPE=EXTRACT FOLDER=* FILE=ErrorURL.csv\n";
iimPlay(macro4);
}
I m able to get the following error in the display .

Code: Select all

Error Found:RuntimeError: element A specified by TXT:Discussion was not found, line 2retcode:-921
not sure why the file is not getting created though :?
do you think its a version specific ?
After a while i modified the code to check the error in the macro4 execution here is what i found

Code: Select all

if (retcode2 < 0) {  
iimDisplay("Error Found:"+Errorstring+"retcode:"+retcode2);
macro4 += "CODE:";
macro4 += "ADD !EXTRACT {{!URLCURRENT}}" + "\n"; 
macro4 += "SAVEAS TYPE=EXTRACT FOLDER=* FILE=ErrorURL.csv\n";
retcode3=iimPlay(macro4);
Errorstring=iimGetLastError();
iimDisplay("Error Found:"+Errorstring+"retcode:"+retcode3);
}
output:

Code: Select all

Error Found:File undefinedCODE:ADD !EXTRACT {{!URLCURRENT}}
SAVEAS TYPE=EXTRACT FOLDER=* FILE=ErrorURL.csv
.iimdoes not existretcode:-930
pinga123
Posts: 20
Joined: Thu May 19, 2016 7:43 am

Re: Help with Imacros with javascript.

Post by pinga123 » Fri Jun 03, 2016 1:21 pm

please help . :) bumping the thread in case someone missed it .
User avatar
thecoder2012
Posts: 427
Joined: Sat Aug 15, 2015 5:14 pm
Location: Internet
Contact:

Re: Help with Imacros with javascript.

Post by thecoder2012 » Thu Jan 23, 2020 8:16 pm

pinga123 wrote:
Fri Jun 03, 2016 1:21 pm
please help . :) bumping the thread in case someone missed it .
You can try SET !ERRORIGNORE YES or make a new full test example WITH test urls (e.g. groupurl.txt\) in this case.
Join 9kw.eu Captcha Service now and let your iMacros continue downloads and scripts while you sleep. - Custom iMacros? Contact me! :idea:
access2vivek
Posts: 69
Joined: Wed Dec 20, 2017 10:00 am
Location: New Delhi, India
Contact:

Re: Help with Imacros with javascript.

Post by access2vivek » Sun Jun 14, 2020 8:49 am

Code: Select all

if (retcode2 < 0) {  
iimDisplay("Error Found:"+Errorstring+"retcode:"+retcode2);
macro4 += "CODE:";
macro4 += "ADD !EXTRACT {{!URLCURRENT}}" + "\n"; 
macro4 += "SAVEAS TYPE=EXTRACT FOLDER=* FILE=ErrorURL.csv\n";
iimPlay(macro4);
}
if you have defined the variable macro4 as var macro4, I think I see where the problem is.
In the 3rd line of the code, you have written

Code: Select all

macro4+="CODE:";
JavaScript error: When we use + in JavaScript, it adds to the text that was previously present. So, if you are running this piece of code inside a loop, or you haven't initiated the macro4 variable, you will get an error. Therefore, simply remove the + sign and write is as:

Code: Select all

macro4="CODE:":
// Rest of your code
iMacros Error: For using iimPlay(), your input string should start with "CODE:". In your earlier code, if the variable was just created, your string would start with "undefinedCODE:" as the variable is initially undefined. Here is the code that shows this concept.

Code: Select all

var temp;
temp+="CODE:";
alert(temp);
I hope it helps :-)
Robust iMacros development with quick turnaround time. Drop an email at "access2content@gmail.com" with your project details.
Post Reply