Calling .js file from within an .iim

Discussions and Tech Support related to the iMacros Firefox Add-on, including the built-in Javascript scripting interface for playing .js files.
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
tammyohagan
Posts: 13
Joined: Sun May 31, 2015 3:18 pm

Calling .js file from within an .iim

Post by tammyohagan » Mon Mar 28, 2016 11:11 pm

Hello!

I am using:
FireFox 43.0
Windows 7

I am trying to figure out how to make a .js file play from within my .iim file.

Here is my .iim

Code: Select all

TAG POS=1 TYPE=INPUT:EMAIL FORM=ID:loginForm ATTR=ID:loginEmail CONTENT=*****
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=ID:loginForm ATTR=ID:loginPassword CONTENT=*****
TAG POS=1 TYPE=BUTTON FORM=ID:loginForm ATTR=TXT:Login
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ID:Form ATTR=NAME:newsletter CONTENT=NO
TAG POS=2 TYPE=INPUT:CHECKBOX FORM=ID:Form ATTR=NAME:newsletter CONTENT=NO
TAG POS=1 TYPE=BUTTON FORM=ID:Form ATTR=TXT:Enter
EVENT TYPE=CLICK SELECTOR="#sm_item_click_area2" BUTTON=0
FRAME F=2
EVENT TYPE=CLICK SELECTOR="#sm_large_play_btn_vpaid" BUTTON=0
FRAME F=0
EVENT TYPE=CLICK SELECTOR="#sm_finish_btn" BUTTON=0
at this point, I need a .js file to run.

Can anyone help me?
User avatar
thecoder2012
Posts: 288
Joined: Sat Aug 15, 2015 5:14 pm
Location: Internet
Contact:

Re: Calling .js file from within an .iim

Post by thecoder2012 » Mon Mar 28, 2016 11:52 pm

tammyohagan wrote:at this point, I need a .js file to run.
It's better to play your iim file in your js file like iimPlay("yourfile.iim")
tammyohagan wrote:Can anyone help me?
Make a separate java-script file and then call it from your macro using
URL GOTO=imacros://run/?m=your-javascript.js
Join 9kw.eu Captcha Service now and let your iMacros continue downloads and scripts while you sleep. - Custom iMacros? Contact me! :idea:
subrand0m
Posts: 8
Joined: Mon Apr 20, 2015 12:07 am

Re: Calling .js file from within an .iim

Post by subrand0m » Tue Mar 29, 2016 11:26 pm

This is the exact question I had recently, My follow up question is, after this new JS script runs does it go back to the old script?

I am Asking as I would like to make my script run using imacro more so than js, but I need JS to run in the middle of the script for a captcha solver.

Also I have been informed that JS does not like to loop in the same way that imacro does where imacro moves to the next line. I have been told this is much harder in JS.
User avatar
thecoder2012
Posts: 288
Joined: Sat Aug 15, 2015 5:14 pm
Location: Internet
Contact:

Re: Calling .js file from within an .iim

Post by thecoder2012 » Wed Mar 30, 2016 12:04 pm

subrand0m wrote:This is the exact question I had recently, My follow up question is, after this new JS script runs does it go back to the old script?
No but you can use iim => js => iim with 3 files and url goto.
subrand0m wrote:I am Asking as I would like to make my script run using imacro more so than js, but I need JS to run in the middle of the script for a captcha solver.
You can use JS as main script with iimPlay to use other iim and js files.
subrand0m wrote:Also I have been informed that JS does not like to loop in the same way that imacro does where imacro moves to the next line. I have been told this is much harder in JS.
Not really. Loops are easy in JS.

Small example in JS:

Code: Select all

var max_loop = 10;
for(var loop = 1; loop <= max_loop; loop++){
// your code
}
Join 9kw.eu Captcha Service now and let your iMacros continue downloads and scripts while you sleep. - Custom iMacros? Contact me! :idea:
subrand0m
Posts: 8
Joined: Mon Apr 20, 2015 12:07 am

Re: Calling .js file from within an .iim

Post by subrand0m » Wed Mar 30, 2016 8:28 pm

Well and I am sorry for Hijacking this topic, but it was relevant to my issues.

Code: Select all

SET !EXTRACT_TEST_POPUP NO
SET !ERRORIGNORE YES
SET !ERRORCONTINUNE YES
SET !DATASOURCE C:\logins.csv
SET !DATASOURCE_COLUMNS 3
SET !DATASOURCE_LINE {{!LOOP}}
TAB T=1
URL GOTO=https://website/index
CLICK X=784 Y=462
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:signup-form ATTR=ID:signup-username CONTENT={{!COL2}}
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=ID:signup-form ATTR=ID:password CONTENT={{!COL3}}
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:signup-form ATTR=ID:email CONTENT={{!COL1}}
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ID:signup-form ATTR=ID:terms CONTENT=YES
URL GOTO=imacros://run/?m=recaptcha.js
TAG POS=1 TYPE=BUTTON FORM=ID:signup-form ATTR=ID:submit
wait seconds = 10
This would be ideal as it would allow me to loop the login using the csv for email/username/password and using what I believe to be your captcha JS script. It is for that site in your signature.
chivracq
Posts: 8319
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Calling .js file from within an .iim

Post by chivracq » Thu Mar 31, 2016 3:23 am

subrand0m wrote:Well and I am sorry for Hijacking this topic, but it was relevant to my issues.

Code: Select all

SET !EXTRACT_TEST_POPUP NO
SET !ERRORIGNORE YES
SET !ERRORCONTINUNE YES
SET !DATASOURCE C:\logins.csv
SET !DATASOURCE_COLUMNS 3
SET !DATASOURCE_LINE {{!LOOP}}
TAB T=1
URL GOTO=https://website/index
CLICK X=784 Y=462
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:signup-form ATTR=ID:signup-username CONTENT={{!COL2}}
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=ID:signup-form ATTR=ID:password CONTENT={{!COL3}}
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:signup-form ATTR=ID:email CONTENT={{!COL1}}
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ID:signup-form ATTR=ID:terms CONTENT=YES
URL GOTO=imacros://run/?m=recaptcha.js
TAG POS=1 TYPE=BUTTON FORM=ID:signup-form ATTR=ID:submit
wait seconds = 10
This would be ideal as it would allow me to loop the login using the csv for email/username/password and using what I believe to be your captcha JS script. It is for that site in your signature.
Pff, wanted to post some Reply, got lost in the 'Save Draft' ones, check my Posts for what I could be saying... :idea:
=> FCIM...! :mrgreen: (Read my Sig...)

=> iMacros Version not even mentioned, ah-ah...! :roll:
Last edited by chivracq on Sat Jun 08, 2019 2:35 am, edited 1 time in total.
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
tammyohagan
Posts: 13
Joined: Sun May 31, 2015 3:18 pm

Re: Calling .js file from within an .iim

Post by tammyohagan » Thu Mar 31, 2016 11:37 am

Thank you thecoder2012 helped!
subrand0m
Posts: 8
Joined: Mon Apr 20, 2015 12:07 am

Re: Calling .js file from within an .iim

Post by subrand0m » Thu Mar 31, 2016 9:16 pm

chivracq wrote:
subrand0m wrote:Well and I am sorry for Hijacking this topic, but it was relevant to my issues.

Code: Select all

SET !EXTRACT_TEST_POPUP NO
SET !ERRORIGNORE YES
SET !ERRORCONTINUNE YES
SET !DATASOURCE C:\logins.csv
SET !DATASOURCE_COLUMNS 3
SET !DATASOURCE_LINE {{!LOOP}}
TAB T=1
URL GOTO=https://website/index
CLICK X=784 Y=462
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:signup-form ATTR=ID:signup-username CONTENT={{!COL2}}
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=ID:signup-form ATTR=ID:password CONTENT={{!COL3}}
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:signup-form ATTR=ID:email CONTENT={{!COL1}}
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ID:signup-form ATTR=ID:terms CONTENT=YES
URL GOTO=imacros://run/?m=recaptcha.js
TAG POS=1 TYPE=BUTTON FORM=ID:signup-form ATTR=ID:submit
wait seconds = 10
This would be ideal as it would allow me to loop the login using the csv for email/username/password and using what I believe to be your captcha JS script. It is for that site in your signature.
Pff, wanted to post some Reply, got lost in the 'Save Draft' ones, check my Posts for what I could be saying...
Sadly I must be over looking something as I do not see what you are referencing.
chivracq
Posts: 8319
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Calling .js file from within an .iim

Post by chivracq » Thu Mar 31, 2016 9:36 pm

subrand0m wrote:Sadly I must be over looking something as I do not see what you are referencing.
You had some interesting Thread a while ago (hum, already nearly 1 year ago, time flies...) to which I never replied because you had not mentioned your FCI as I only reply to Threads where Users mention their FCI (like stated in the Forum Rules..., read my Sig...) and that was nearly a pity because that Thread of yours was pretty interesting I remember thinking then, you should update it with your FCI and some Update if you managed to solve it... and bump it anyway if you are still looking for some Answer...
Neat Follow-up on all their Threads (and sharing their Solution) is another of my "Conditions" for helping other Users... :idea:
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
subrand0m
Posts: 8
Joined: Mon Apr 20, 2015 12:07 am

Re: Calling .js file from within an .iim

Post by subrand0m » Fri Apr 01, 2016 12:47 am

chivracq wrote:
subrand0m wrote:Sadly I must be over looking something as I do not see what you are referencing.
You had some interesting Thread a while ago (hum, already nearly 1 year ago, time flies...) to which I never replied because you had not mentioned your FCI as I only reply to Threads where Users mention their FCI (like stated in the Forum Rules..., read my Sig...) and that was nearly a pity because that Thread of yours was pretty interesting I remember thinking then, you should update it with your FCI and some Update if you managed to solve it... and bump it anyway if you are still looking for some Answer...
Neat Follow-up on all their Threads (and sharing their Solution) is another of my "Conditions" for helping other Users... :idea:
Sadly I am still a HUGE NOOB and did not even realize that, was needed so thank you for informing me. in addition, I never solved the other one, I found a work around using a totally different method to achieve what I was looking to do.

Current Setup:
Firefox 45.0.0.1
Windows 10 pro x64bit
iMacro for firefox 8.9.6

Code:

Code: Select all

SET !EXTRACT_TEST_POPUP NO
SET !ERRORIGNORE YES
SET !ERRORCONTINUNE YES
SET !DATASOURCE C:\logins.csv
SET !DATASOURCE_COLUMNS 3
SET !DATASOURCE_LINE {{!LOOP}}
TAB T=1
URL GOTO=https://website/index
CLICK X=784 Y=462
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:signup-form ATTR=ID:signup-username CONTENT={{!COL2}}
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=ID:signup-form ATTR=ID:password CONTENT={{!COL3}}
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:signup-form ATTR=ID:email CONTENT={{!COL1}}
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ID:signup-form ATTR=ID:terms CONTENT=YES
URL GOTO=imacros://run/?m=recaptcha.js
TAG POS=1 TYPE=BUTTON FORM=ID:signin-form ATTR=ID:submit
wait seconds = 10
Is for my current one, honestly if we find a solution for this it would answer the other question also.

The Above script works. Up to the point of running the .js script, it then just ends without returning to the original script and running the submit button to login.
chivracq
Posts: 8319
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Calling .js file from within an .iim

Post by chivracq » Fri Apr 01, 2016 4:13 am

subrand0m wrote:Sadly I am still a HUGE NOOB and did not even realize that, was needed so thank you for informing me. in addition, I never solved the other one, I found a work around using a totally different method to achieve what I was looking to do.

Current Setup:

Code: Select all

Firefox 45.0.0.1
Windows 10 pro x64bit
iMacro for firefox 8.9.6
Code:

Code: Select all

SET !EXTRACT_TEST_POPUP NO
SET !ERRORIGNORE YES
SET !ERRORCONTINUNE YES
SET !DATASOURCE C:\logins.csv
SET !DATASOURCE_COLUMNS 3
SET !DATASOURCE_LINE {{!LOOP}}
TAB T=1
URL GOTO=https://website/index
CLICK X=784 Y=462
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:signup-form ATTR=ID:signup-username CONTENT={{!COL2}}
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=ID:signup-form ATTR=ID:password CONTENT={{!COL3}}
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:signup-form ATTR=ID:email CONTENT={{!COL1}}
TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ID:signup-form ATTR=ID:terms CONTENT=YES
URL GOTO=imacros://run/?m=recaptcha.js
TAG POS=1 TYPE=BUTTON FORM=ID:signin-form ATTR=ID:submit
wait seconds = 10
Is for my current one, honestly if we find a solution for this it would answer the other question also.

The Above script works. Up to the point of running the .js script, it then just ends without returning to the original script and running the submit button to login.
Woaw...!, huge Quality Improvement of the 2 Threads where you posted, and Compliments for the nice and friendly tone, most (new) Users just get angry when I ask them for their FCI pointing at that they didn't bother to read the Forum Rules for Required Info that I mostly don't dare/care anymore to ask for it...

Beeeeh..., yep, normal, only 'iimPlay()' from a '.js' Script knows that a ('.iim') Sub-Macro is being run and will wait until it finishes (with some Return-Code), but when using the 'run/?m=' Syntax, the newly launched Macro "thinks" it is the almighty King in its Kingdom (= Robinson Crusoe on his deserted Island...! (hum..., and forget about Friday, it's nearly WE...!!)), so you need to split the Logic of your '.iim' Macro into 2 Macros and have your '.js' Script call the 2nd part of the '.iim' Logic (which will only contain the last 2 Lines of your current Macro) at the end of it...

But the 'run/?m=' Syntax is always a kind of a Workaround, TechSup discourages its Use, the "normal" way for your Scenario would be to have your '.js' Captcha Script be the Main Script calling with 'iimPlay()' the first part of your '.iim' Logic, then do the '.js' Captcha Logic, then call the second part of the '.iim' Logic.
'run/?m=' has some Drawbacks about heavy Focus Stealing if you use several Instances of the same Browser, it only works a bit fine in a Dedicated FF Profile...
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
subrand0m
Posts: 8
Joined: Mon Apr 20, 2015 12:07 am

Re: Calling .js file from within an .iim

Post by subrand0m » Fri Apr 01, 2016 6:15 pm

chivracq wrote: Woaw...!, huge Quality Improvement of the 2 Threads where you posted, and Compliments for the nice and friendly tone, most (new) Users just get angry when I ask them for their FCI pointing at that they didn't bother to read the Forum Rules for Required Info that I mostly don't dare/care anymore to ask for it...

Beeeeh..., yep, normal, only 'iimPlay()' from a '.js' Script knows that a ('.iim') Sub-Macro is being run and will wait until it finishes (with some Return-Code), but when using the 'run/?m=' Syntax, the newly launched Macro "thinks" it is the almighty King in its Kingdom (= Robinson Crusoe on his deserted Island...! (hum..., and forget about Friday, it's nearly WE...!!)), so you need to split the Logic of your '.iim' Macro into 2 Macros and have your '.js' Script call the 2nd part of the '.iim' Logic (which will only contain the last 2 Lines of your current Macro) at the end of it...

But the 'run/?m=' Syntax is always a kind of a Workaround, TechSup discourages its Use, the "normal" way for your Scenario would be to have your '.js' Captcha Script be the Main Script calling with 'iimPlay()' the first part of your '.iim' Logic, then do the '.js' Captcha Logic, then call the second part of the '.iim' Logic.
'run/?m=' has some Drawbacks about heavy Focus Stealing if you use several Instances of the same Browser, it only works a bit fine in a Dedicated FF Profile...

I have writen the full code in the JS and gotten it to work, Kinda, my only issue with that is when doing the loop I am unsure of how to migrate it down the list. With imacro each time it looks it will automagicly move to the next line and simply populate via that new line. I am not going to sit here and claim I know what the hell I am doing. I some how get by playing with imacro and that record feature to pull off the things I have been doing. Stepping into JS is a huge move fro me and I am extremely confused.

Could I do a .JS to do a
iimPlay(Script 1)
iimPlay(Recaptcha)
iimPlay(Script 2)


Would that be an option?


I have been doing some Tinkering in my head on how I can make this work the best I wanted to know if this would be an option
Working_File.js

Code: Select all

for(var i2=1;i2<=0;i2++){
iimplay("script1.iim")
iimplay("recaptcha.js")
if("TAG POS=1 TYPE=DIV ATTR=TXT:Success!\n"){
     var imacros_main6 = "CODE:"+imacros_header;
     imacros_main6 += "wait seconds = 3605\n";
     iimPlay(imacros_main6)
}else{
     iimPlay("recaptcha.js")
}
}
prpawar44
Posts: 1
Joined: Mon Jul 11, 2016 11:05 am

Re: Calling .js file from within an .iim

Post by prpawar44 » Mon Jul 11, 2016 12:20 pm

thecoder2012 wrote:
tammyohagan wrote:at this point, I need a .js file to run.
It's better to play your iim file in your js file like iimPlay("yourfile.iim")
tammyohagan wrote:Can anyone help me?
Make a separate java-script file and then call it from your macro using
URL GOTO=imacros://run/?m=your-javascript.js

I am using this command within my macros script to call .Js file :
URL GOTO=imacros://run/?m=Demo-Chrome/Priya_Chrome/PageLode.js


I am able to call the .js file from .iim in Firefox browser; however I am unable to do the same in Chrome and IE browser.
But it’s giving error as “RuntimeError: Page loading timeout” for above line.
Why it is unable to call .js file save in Demo-Chrome/Priya_Chrome folder?

Also, I tried to run direct .js file as well and it was successfully executed in Firefox browser; however I was unable to call the same in Chrome and IE browser. Is there any different setting I need to do for chrome and IE browser? Even I was unable to view .js file saved in Demo-Chrome

waiting for reply.
welytonlink
Posts: 1
Joined: Sat Jun 08, 2019 1:59 am

Re: Calling .js file from within an .iim

Post by welytonlink » Sat Jun 08, 2019 2:02 am

iimPlay("CODE:URL GOTO=imacros://run/?m=recaptcha.js");
chivracq
Posts: 8319
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Calling .js file from within an .iim

Post by chivracq » Sat Jun 08, 2019 3:00 am

welytonlink wrote:
Sat Jun 08, 2019 2:02 am
iimPlay("CODE:URL GOTO=imacros://run/?m=recaptcha.js");
Yeah, Thanks for posting but when posting an Answer "3 years later" 8) , you should mention in which FCI you've tested your Solution... :P
... But it's not the correct Solution anyway...! 'iimPlay()' is a '.js' Command, the Thread is about "Calling .js file from within an .iim", so it can't work...!

What you are posting is the Syntax/Workaround for calling a '.js' Script from a '.js' Script using iMacros for FF until v9.0.3, and without using the 'Scripting Interface'..., (which "natively" supports calling a '.js' Script from 'iimPlay()'), but you are one Embedded Level too far, ah-ah...! :oops:
But Thanks for posting anyway of course... :wink:

This Syntax/Workaround btw is never a really "Good Practice" in my Opinion... And I am still waiting for a "valid" Reason to want to call a '.js' Script from another '.js' Script..., ah-ah...! :twisted:
(And iMacros/the FF JS Runtime Engine loses very quickly track of which '.js' is the "main" '.js' Script supposed to be in control of the whole Workflow of the Script..., which leads to some "unexpected" Behaviour... + Passing Vars from one '.js' to another (Sub-)'.js' is not very straightforward either...)
Yeah..., I had already done a mini-bit of Thinking about it, and hum..., I do have one "mini-tiny-mini-" (very specific) Usecase for it..., but pfff..., still not convinced, Bad Practice in 99% of the Cases, and even in that 1% Case, I would find a "better" Workflow... :evil:
That mini-Usecase is for dynamically building a (different) Test Suite or Test Set for different Runs, and each Test Case would be one of those Sub-'.js' Scripts, but Test Cases could rather be "directly" '.iim' Scripts, or maybe for those Sub-'.js' Scripts to group Test Cases together to imitate a bit a Folder Structure, but I find it pretty cumbersome, and there are better Tools than iMacros to do that, where that Functionality is already implemented OOTB, and even with a much simpler Click-Click-Click GUI Interface...
Ah oops, hum-hum, another Usecase, partly for "Modularity" and Maintenance, (to avoid repeating and maintaining the same Code in different Places/Macros), but especially for being able to use 'iimDisplay()' as some kind of Function... Hum, and again, I think there is/are (a) better Solution(s).... :shock:


Previous User @prpawar44 had posted the correct Solution:
Make a separate java-script file and then call it from your macro using

Code: Select all

URL GOTO=imacros://run/?m=your-javascript.js
Thread from 3 years ago now, was a bit "too messy" then, with "too many" Participants in the Thread, most not mentioning their FCI, I had not bothered to "clean the Mess" then... OK, I do it "now" (3 years later, June 2019), Thanks to @welytonlink, kind of reviving this Thread... 8)

But that Syntax did/will only work using iMacros for FF v8.9.7 (or v9.0.3 for FF), but v8.9.7 is the best FCI... (+ FF v55.0.3 or PM v28), which also "answers" the "however I am unable to do the same in Chrome and IE browser." from the same User... (Only iMacros for FF until v9.0.3 supports '.js' Scripts...)
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
Post Reply