Trouble with VBS and running multiple scripts

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

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
adam1337
Posts: 16
Joined: Sun Jun 09, 2019 4:12 pm

Trouble with VBS and running multiple scripts

Post by adam1337 » Sun Jun 09, 2019 5:01 pm

iMacros version: iMacros Browser (x86) version 12.5.503.8802
Operating system: Windows 10 64-bit English
Browser: Internet Explorer version 11.504.17763.0 (iMacros Browser/client, not using browser extension).
Demo success: Yes

I'm using the following script to 1) login to a website, 2) loop through a 1-column csv file and use each value to make a selection from a dropdown menu, 3) submit selection, and 4) select the download link based on <a> tag content

Code: Select all

VERSION BUILD=12.5.503.8802
TAB T=1     
TAB CLOSEALLOTHERS 
' Go to login portal
URL GOTO=[login url]
' Sign-in
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:userId CONTENT=[userid]
SET !ENCRYPTION STOREDKEY
TAG POS=1 TYPE=INPUT:PASSWORD ATTR=NAME:password CONTENT=[pw]
TAG POS=1 TYPE=INPUT:SUBMIT ATTR=NAME:signin
WAIT SECONDS=10
'set csv file as datasource
SET !DATASOURCE accountlist.csv
SET !DATASOURCE_LINE {{!LOOP}}
'Set download path
ONDOWNLOAD FOLDER=E:\Folder\ FILE={{!COL1}}+document+{{!NOW:yymmdd}} WAIT=YES
SET !TIMEOUT_DOWNLOAD 20
WAIT SECONDS=3
TAG POS=1 TYPE=SELECT FORM=NAME:NoFormName ATTR=CLASS:GB01FU-BNW CONTENT=%*{{!COL1}}*
WAIT SECONDS=3
'Choose 'go' to submit selection from dropdown
TAG POS=1 TYPE=BUTTON ATTR=TXT:GO
'Click download link
TAG POS=1 TYPE=A ATTR=TXT:Download
WAIT SECONDS=10
CSV Example

Code: Select all

112314003
140234011
140074029
422407607
Since I do not want the script to loop through the login process, rather just the downloading part, I followed the docs here: https://wiki.imacros.net/Loop_after_Query_or_Login to create a VBS script which will run the scripts sequentially and loop only the desired script:

Code: Select all

Option Explicit
Dim iim1, iret

'initialize iMacros instance
set iim1 = CreateObject ("imacros")
iret = iim1.iimOpen()

'here comes the code
'query
Dim login
login = "URL GOTO=[login url]" & vbNewLine
login = login & "TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:userId CONTENT=[userid]" & vbNewLine
login = login & "SET !ENCRYPTION STOREDKEY" & vbNewLine
login = login & "TAG POS=1 TYPE=INPUT:PASSWORD ATTR=NAME:password CONTENT=[pw]" & vbNewLine
login = login & "WAIT SECONDS=2" & vbNewLine
login = login & "TAG POS=1 TYPE=INPUT:SUBMIT ATTR=NAME:signin" & vbNewLine
login = login & "WAIT SECONDS=15" & vbNewLine
iret = iim1.iimPlayCode(login)

Dim macro
macro = "SET !DATASOURCE accountlist.csv" & vbNewLine
macro = macro & "SET !DATASOURCE_LINE {{!LOOP}}" & vbNewLine
macro = macro & "ONDOWNLOAD FOLDER=E:\Folder\ FILE={{!COL1}}+Statement+{{!NOW:yymmdd}} WAIT=YES" & vbNewLine
macro = macro & "SET !TIMEOUT_DOWNLOAD 20" & vbNewLine
macro = macro & "WAIT SECONDS=3" & vbNewLine
macro = macro & "TAG POS=1 TYPE=SELECT FORM=NAME:NoFormName ATTR=CLASS:GB01FU-BNW CONTENT=%*{{!COL1}}*" & vbNewLine
macro = macro & "WAIT SECONDS=3" & vbNewLine
macro = macro & "TAG POS=1 TYPE=BUTTON ATTR=TXT:GO" & vbNewLine
macro = macro & "WAIT SECONDS=3" & vbNewLine
macro = macro & "TAG POS={{loopNumber}} TYPE=A ATTR=TXT:Download" & vbNewLine
macro = macro & "WAIT SECONDS=3" & vbNewLine

Dim recentLineNumber
recentLineNumber = 0

do while not iret < 0 
	recentLineNumber = recentLineNumber + 1
	iret = iim1.iimSet("loopNumber", Cstr(recentLineNumber))
	iret = iim1.iimPlayCode(macro)
loop

' tell user we're done
msgbox CStr((recentLineNumber-1)) & " statements saved. End."

' exit iMacros instance and quit script
iret = iim1.iimClose()
Wscript.Quit(iret)
The first macro (login) works fine when initiated through VBS script, but the second macro (macro) which loops through the CSV does not (it does not properly select the <a> tag to download). I may be able to use EVENT and CLICK to get it working through VBS, but I would rather maintain the current structure to avoid errors if multiple CSS selectors or element structure change later down the road.

When I run the second part of the script on its own in the iMacros browser using the UI "repeat" fields, it works perfectly.

Code: Select all

VERSION BUILD=12.5.503.8802
TAB T=1     
TAB CLOSEALLOTHERS 
SET !DATASOURCE accountlist.csv
SET !DATASOURCE_LINE {{!LOOP}}
'SET !PLAYBACKDELAY 0.00
'set path and filename
ONDOWNLOAD FOLDER=E:\Folder\ FILE={{!COL1}}+Statement+{{!NOW:yymmdd}} WAIT=YES
SET !TIMEOUT_DOWNLOAD 20
WAIT SECONDS=3
'select from dropdown
TAG POS=1 TYPE=SELECT FORM=NAME:NoFormName ATTR=CLASS:GB01FU-BNW CONTENT=%*{{!COL1}}*
WAIT SECONDS=3
'select 'go' to submit selection
TAG POS=1 TYPE=BUTTON ATTR=TXT:GO
'select <a> tag to download
TAG POS=1 TYPE=A ATTR=TXT:Download
WAIT SECONDS=10
I'm wondering now if VBS is optimal for this, or if I should use some other method to run the scripts separately and loop only the second one. After browsing the forum, I found this post viewtopic.php?t=24115 where chivaracq suggested .js may not be optimal either. A possible solution is provided "2- Approach Nb 2:" which may be a good solution but I can't seem to find examples which are applicable to my case. It's referring to URLs which appear to be relevant to iMacros for firefox, but I'm trying to keep everything in the iMacros browser as I'll be purchasing pro or enterprise when the trial is over.

Never touched VBS before this but I'm glad I did...that said I'm open to learning what may be necessary to accomplish this in the most efficient way.

Any guidance/suggestions/insight will be greatly appreciated.

Edit: Fixed typo
Last edited by adam1337 on Wed Jun 12, 2019 4:45 pm, edited 1 time in total.
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Trouble with VBS and running multiple scripts

Post by chivracq » Tue Jun 11, 2019 4:35 pm

adam1337 wrote:
Sun Jun 09, 2019 5:01 pm
iMacros version: iMacros Browser (x86) version 12.5.503.8802
Opearting system: Windows 10 64-bit English
Browser: Internet Explorer version 11.504.17763.0 (iMacros Browser/client, not using browser extension).
Demo success: Yes
I'm using the following script to 1) login to a website, 2) loop through a 1-column csv file and use each value to make a selection from a dropdown menu, 3) submit selection, and 4) select the download link based on <a> tag content

Code: Select all

VERSION BUILD=12.5.503.8802
TAB T=1     
TAB CLOSEALLOTHERS 
' Go to login portal
URL GOTO=[login url]
' Sign-in
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:userId CONTENT=[userid]
SET !ENCRYPTION STOREDKEY
TAG POS=1 TYPE=INPUT:PASSWORD ATTR=NAME:password CONTENT=[pw]
TAG POS=1 TYPE=INPUT:SUBMIT ATTR=NAME:signin
WAIT SECONDS=10
'set csv file as datasource
SET !DATASOURCE accountlist.csv
SET !DATASOURCE_LINE {{!LOOP}}
'Set download path
ONDOWNLOAD FOLDER=E:\Folder\ FILE={{!COL1}}+document+{{!NOW:yymmdd}} WAIT=YES
SET !TIMEOUT_DOWNLOAD 20
WAIT SECONDS=3
TAG POS=1 TYPE=SELECT FORM=NAME:NoFormName ATTR=CLASS:GB01FU-BNW CONTENT=%*{{!COL1}}*
WAIT SECONDS=3
'Choose 'go' to submit selection from dropdown
TAG POS=1 TYPE=BUTTON ATTR=TXT:GO
'Click download link
TAG POS=1 TYPE=A ATTR=TXT:Download
WAIT SECONDS=10
CSV Example

Code: Select all

112314003
140234011
140074029
422407607
Since I do not want the script to loop through the login process, rather just the downloading part, I followed the docs here: https://wiki.imacros.net/Loop_after_Query_or_Login to create a VBS script which will run the scripts sequentially and loop only the desired script:

Code: Select all

Option Explicit
Dim iim1, iret

'initialize iMacros instance
set iim1 = CreateObject ("imacros")
iret = iim1.iimOpen()

'here comes the code
'query
Dim login
login = "URL GOTO=[login url]" & vbNewLine
login = login & "TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:userId CONTENT=[userid]" & vbNewLine
login = login & "SET !ENCRYPTION STOREDKEY" & vbNewLine
login = login & "TAG POS=1 TYPE=INPUT:PASSWORD ATTR=NAME:password CONTENT=[pw]" & vbNewLine
login = login & "WAIT SECONDS=2" & vbNewLine
login = login & "TAG POS=1 TYPE=INPUT:SUBMIT ATTR=NAME:signin" & vbNewLine
login = login & "WAIT SECONDS=15" & vbNewLine
iret = iim1.iimPlayCode(login)

Dim macro
macro = "SET !DATASOURCE accountlist.csv" & vbNewLine
macro = macro & "SET !DATASOURCE_LINE {{!LOOP}}" & vbNewLine
macro = macro & "ONDOWNLOAD FOLDER=E:\Folder\ FILE={{!COL1}}+Statement+{{!NOW:yymmdd}} WAIT=YES" & vbNewLine
macro = macro & "SET !TIMEOUT_DOWNLOAD 20" & vbNewLine
macro = macro & "WAIT SECONDS=3" & vbNewLine
macro = macro & "TAG POS=1 TYPE=SELECT FORM=NAME:NoFormName ATTR=CLASS:GB01FU-BNW CONTENT=%*{{!COL1}}*" & vbNewLine
macro = macro & "WAIT SECONDS=3" & vbNewLine
macro = macro & "TAG POS=1 TYPE=BUTTON ATTR=TXT:GO" & vbNewLine
macro = macro & "WAIT SECONDS=3" & vbNewLine
macro = macro & "TAG POS={{loopNumber}} TYPE=A ATTR=TXT:Download" & vbNewLine
macro = macro & "WAIT SECONDS=3" & vbNewLine

Dim recentLineNumber
recentLineNumber = 0

do while not iret < 0 
	recentLineNumber = recentLineNumber + 1
	iret = iim1.iimSet("loopNumber", Cstr(recentLineNumber))
	iret = iim1.iimPlayCode(macro)
loop

' tell user we're done
msgbox CStr((recentLineNumber-1)) & " statements saved. End."

' exit iMacros instance and quit script
iret = iim1.iimClose()
Wscript.Quit(iret)
The first macro (login) works fine when initiated through VBS script, but the second macro (macro) which loops through the CSV does not (it does not properly select the <a> tag to download). I may be able to use EVENT and CLICK to get it working through VBS, but I would rather maintain the current structure to avoid errors if multiple CSS selectors or element structure change later down the road.

When I run the second part of the script on its own in the iMacros browser using the UI "repeat" fields, it works perfectly.

Code: Select all

VERSION BUILD=12.5.503.8802
TAB T=1     
TAB CLOSEALLOTHERS 
SET !DATASOURCE accountlist.csv
SET !DATASOURCE_LINE {{!LOOP}}
'SET !PLAYBACKDELAY 0.00
'set path and filename
ONDOWNLOAD FOLDER=E:\Folder\ FILE={{!COL1}}+Statement+{{!NOW:yymmdd}} WAIT=YES
SET !TIMEOUT_DOWNLOAD 20
WAIT SECONDS=3
'select from dropdown
TAG POS=1 TYPE=SELECT FORM=NAME:NoFormName ATTR=CLASS:GB01FU-BNW CONTENT=%*{{!COL1}}*
WAIT SECONDS=3
'select 'go' to submit selection
TAG POS=1 TYPE=BUTTON ATTR=TXT:GO
'select <a> tag to download
TAG POS=1 TYPE=A ATTR=TXT:Download
WAIT SECONDS=10
I'm wondering now if VBS is optimal for this, or if I should use some other method to run the scripts separately and loop only the second one. After browsing the forum, I found this post viewtopic.php?t=24115 where chivaracq suggested .js may not be optimal either. A possible solution is provided "2- Approach Nb 2:" which may be a good solution but I can't seem to find examples which are applicable to my case. It's referring to URLs which appear to be relevant to iMacros for firefox, but I'm trying to keep everything in the iMacros browser as I'll be purchasing pro or enterprise when the trial is over.

Never touched VBS before this but I'm glad I did...that said I'm open to learning what may be necessary to accomplish this in the most efficient way.

Any guidance/suggestions/insight will be greatly appreciated.
Alright...!, I had seen your Thread when you had opened it on Sunday and had quickly had the time to approve it before going to some Festival where I didn't have any Internet for 2 days, arrggghhh...! Just back...

OK, a few Thoughts, and I hardly know anything about '.vbs', ah-ah...!

1- Hum, Interesting Thread indeed, that "older" Thread from 4 years ago now, pity the User never followed up, I guess they probably found a Solution and didn't bother to update their Thread and to share their Solution/Final Script anymore... :shock:

2- The 'Cstr' in your "iret = iim1.iimSet("loopNumber", Cstr(recentLineNumber))" is supposed to be "CStr" and not "Cstr". I'm not sure if '.vbs' is Case Sensitive (like '.js'), but that could be the Pb... :idea:

3- You can add a "PROMPT {{loopNumber}}" in your on-the-fly '.iim' Macro to check and follow that Var.

4- I'm not sure the 'CStr()' is actually really necessary, I would think that "iret = iim1.iimSet("loopNumber", recentLineNumber)" is probably already "good enough"...

5- The following Line in your '.vbs':

Code: Select all

macro = macro & "TAG POS={{loopNumber}} TYPE=A ATTR=TXT:Download" & vbNewLine
is "converted" to:

Code: Select all

'select <a> tag to download
TAG POS=1 TYPE=A ATTR=TXT:Download
... in the pure '.iim' Script where you say "When I run the second part of the script on its own in the iMacros browser using the UI "repeat" fields, it works perfectly."
Both Statements are not the same... Is the 'POS' always "1" or does it need to be incremented...? Then your '.iim' in Looping Mode should read:

Code: Select all

'select <a> tag to download
TAG POS={{!LOOP}} TYPE=A ATTR=TXT:Download
6-Hum, I have to leave now, I'll come back a bit later, but the following part can easily be done "Conditional" to be executed only on '!LOOP'=1 using 'EVAL()', to implement your Scenario in just 1 '.iim' Script, no need for '.vbs' (or '.js' or whatever)...:

Code: Select all

' Go to login portal
URL GOTO=[login url]
' Sign-in
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:userId CONTENT=[userid]
SET !ENCRYPTION STOREDKEY
TAG POS=1 TYPE=INPUT:PASSWORD ATTR=NAME:password CONTENT=[pw]
TAG POS=1 TYPE=INPUT:SUBMIT ATTR=NAME:signin
WAIT SECONDS=10
Last edited by chivracq on Wed Jun 12, 2019 4:32 pm, edited 1 time in total.
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
adam1337
Posts: 16
Joined: Sun Jun 09, 2019 4:12 pm

Re: Trouble with VBS and running multiple scripts

Post by adam1337 » Tue Jun 11, 2019 6:33 pm

Thanks for your reply.

Code: Select all

2- The 'Cstr' in your "iret = iim1.iimSet("loopNumber", Cstr(recentLineNumber))" is supposed to be "CStr" and not "Cstr". I'm not sure if '.vbs' is Case Sensitive (like '.js'), but that could be the Pb...  :idea: 
I changed the 'S' in 'CStr' to a lowercase 's' though it did not make a difference.

Code: Select all

5- The following Line in your '.vbs':
Code: Select all

macro = macro & "TAG POS={{loopNumber}} TYPE=A ATTR=TXT:Download" & vbNewLine
is "converted" to:
Code: Select all

'select <a> tag to download
TAG POS=1 TYPE=A ATTR=TXT:Download
... in the pure '.iim' Script where you say "When I run the second part of the script on its own in the iMacros browser using the UI "repeat" fields, it works perfectly."
Both Statements are not the same... Is the 'POS' always "1" or does it need to be incremented...? Then your '.iim' in Looping Mode should read:
Code: Select all

'select <a> tag to download
TAG POS={{!LOOP}} TYPE=A ATTR=TXT:Download
This resolved the main issue of the <a> tag not selecting. Now it properly selects the link. The {{loopnumber}} wasn't implemented properly in my original script as you suggested so by changing the tag to "1" instead, it selected the link.

There is another issue with the script now, specifically with the following line:

Code: Select all

macro = macro & "ONDOWNLOAD FOLDER=E:\Tauber\ FILE={{!COL1}}+Statement+{{!NOW:yymmdd}} WAIT=YES" & vbNewLine
which tells imacro to select a value from a drop down based on the csv value of the current line.

Similar to the behavior we saw before, this line works perfectly on it's own when run from within the imacros browser and with a repeat value explicitly set in the UI.

Code: Select all

TAG POS=1 TYPE=SELECT FORM=NAME:NoFormName ATTR=CLASS:GB01FU-BNW CONTENT=%*{{!COL1}}*
Based on the disparity I'm seeing between running the VBS script and manually executing in browser, I think my (new) issue may be related to how I'm referencing that 'loopnumber'. I could imagine if it was implemented properly it should behave the same, but I'm unsure if the command(s) issued to iMacros when the 'repeat' UI field is set are the same as the seemingly custom 'loopnumber' function which was provided in the VBS example (https://wiki.imacros.net/Loop_after_Query_or_Login).

I ended up purchasing a license today (professional mistakenly, will be upgrading to enterprise to use vbs, for now I reverted to trial) and have shared the issue with the support team. Once I hear back I'll share the solution (with permission) or try to identify an approach that would work in this case.
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Trouble with VBS and running multiple scripts

Post by chivracq » Wed Jun 12, 2019 2:07 am

adam1337 wrote:
Tue Jun 11, 2019 6:33 pm
Thanks for your reply.

Code: Select all

2- The 'Cstr' in your "iret = iim1.iimSet("loopNumber", Cstr(recentLineNumber))" is supposed to be "CStr" and not "Cstr". I'm not sure if '.vbs' is Case Sensitive (like '.js'), but that could be the Pb...  :idea: 
I changed the 'S' in 'CStr' to a lowercase 's' though it did not make a difference.

Code: Select all

5- The following Line in your '.vbs':
Code: Select all

macro = macro & "TAG POS={{loopNumber}} TYPE=A ATTR=TXT:Download" & vbNewLine
is "converted" to:
Code: Select all

'select <a> tag to download
TAG POS=1 TYPE=A ATTR=TXT:Download
... in the pure '.iim' Script where you say "When I run the second part of the script on its own in the iMacros browser using the UI "repeat" fields, it works perfectly."
Both Statements are not the same... Is the 'POS' always "1" or does it need to be incremented...? Then your '.iim' in Looping Mode should read:
Code: Select all

'select <a> tag to download
TAG POS={{!LOOP}} TYPE=A ATTR=TXT:Download
This resolved the main issue of the <a> tag not selecting. Now it properly selects the link. The {{loopnumber}} wasn't implemented properly in my original script as you suggested so by changing the tag to "1" instead, it selected the link.
Ah...!!!, OK, good-good then...! :D
(Even if a bit difficult to "follow" your Reply/ies as you didn't follow my [1-6] systematic Qt's/Suggs...)

But OK, I understand (and will try to remember) that '.vbs' is NOT Case Sensitive with Methods/Commands... ('.js' is, pffoufff...!!!, I had the "Case" recently with 'toLowerCase()' (and not "toLowercase()" like I was trying to use...).)

adam1337 wrote:
Tue Jun 11, 2019 6:33 pm
There is another issue with the script now, specifically with the following line:

Code: Select all

macro = macro & "ONDOWNLOAD FOLDER=E:\Tauber\ FILE={{!COL1}}+Statement+{{!NOW:yymmdd}} WAIT=YES" & vbNewLine
which tells imacro to select a value from a drop down based on the csv value of the current line.

Similar to the behavior we saw before, this line works perfectly on it's own when run from within the imacros browser and with a repeat value explicitly set in the UI.

Code: Select all

TAG POS=1 TYPE=SELECT FORM=NAME:NoFormName ATTR=CLASS:GB01FU-BNW CONTENT=%*{{!COL1}}*
Based on the disparity I'm seeing between running the VBS script and manually executing in browser, I think my (new) issue may be related to how I'm referencing that 'loopnumber'. I could imagine if it was implemented properly it should behave the same, but I'm unsure if the command(s) issued to iMacros when the 'repeat' UI field is set are the same as the seemingly custom 'loopnumber' function which was provided in the VBS example (https://wiki.imacros.net/Loop_after_Query_or_Login).

I ended up purchasing a license today (professional mistakenly, will be upgrading to enterprise to use vbs, for now I reverted to trial) and have shared the issue with the support team. Once I hear back I'll share the solution (with permission) or try to identify an approach that would work in this case.
I ended up purchasing a license today (professional mistakenly, will be upgrading to enterprise to use vbs, for now I reverted to trial) and have shared the issue with the support team.
Hueueueuemmm, yeah, you don't really need any (Enterprise) License for your Scenario, I would think, or maybe only a 'PE' License for v10.x for FF or CR, (for the Looping and FIO File Access for the DataSource and 'SAVEAS'), as I said, your Script can very easily be done in pure '.iim'... Your "Scenario" is very "simple", you don't need any Scripting Interface or any Scripting Language to implement it, ah-ah...! :)
OK, a bit late for me after 2 days DJ'ing 9h + 7h non-stop for some nice Festival, + a "Chill-out" evening, oops...!, but, hum, try this one... (in pure '.iim'):

Code: Select all

VERSION BUILD=12.5.503.8802
SET !ERRORIGNORE YES
SET !TIMEOUT_PAGE 30
SET !TIMEOUT_STEP 0
TAB T=1     
'TAB CLOSEALLOTHERS

'Easy Access Vars:
SET URL_Site [login url]

'Login only on Loop=1:
'=> Conditional Vars for the Login Part:
SET URL_Login EVAL ("var d='{{!LOOP}}', us='{{URL_Site}}'; var z; if(d==1){z=us;} else{z='';}; z;")
SET Loop_1 EVAL ("var d='{{!LOOP}}'; var z; if(d==1){z=1;} else{z=0;}; z;")
SET WAIT_Login ("var d='{{!LOOP}}'; var z; if(d==1){z=10;} else{z=0;}; z;")

'Debug:
SET Debug_Msg LOOP:<SP>_{{!LOOP}}_<BR><BR>URL_Site:<SP>_{{URL_Sir}}_<BR>URL_Login:<SP>_{{URL_Login}}<BR><BR>
ADD Debug_Msg Loop_1<SP>(for<SP>POS):<SP>_{{Loop_1}}_<BR>WAIT_Login:<SP>_{{WAIT_Login}}_
PROMPT {{Debug_Msg}}
PAUSE

' Go to login portal
'URL GOTO=[login url]
URL GOTO={{URL_Login}}

' Sign-in:
'TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:userId CONTENT=[userid]
TAG POS={{Loop_1}} TYPE=INPUT:TEXT ATTR=NAME:userId CONTENT=[userid]
'>
SET !ENCRYPTION STOREDKEY
'TAG POS=1 TYPE=INPUT:PASSWORD ATTR=NAME:password CONTENT=[pw]
TAG POS={{Loop_1}} TYPE=INPUT:PASSWORD ATTR=NAME:password CONTENT=[pw]
'>
'TAG POS=1 TYPE=INPUT:SUBMIT ATTR=NAME:signin
TAG POS={{Loop_1}} TYPE=INPUT:SUBMIT ATTR=NAME:signin
'>
'WAIT SECONDS=10
WAIT SECONDS={{WAIT_Login}}

'Looping Section:
'set csv file as datasource
SET !DATASOURCE accountlist.csv
SET !DATASOURCE_LINE {{!LOOP}}
'Set download path
ONDOWNLOAD FOLDER=E:\Folder\ FILE={{!COL1}}+document+{{!NOW:yymmdd}} WAIT=YES
SET !TIMEOUT_DOWNLOAD 20
WAIT SECONDS=3
TAG POS=1 TYPE=SELECT FORM=NAME:NoFormName ATTR=CLASS:GB01FU-BNW CONTENT=%*{{!COL1}}*
WAIT SECONDS=3
'Choose 'go' to submit selection from dropdown
TAG POS=1 TYPE=BUTTON ATTR=TXT:GO
'Click download link
TAG POS=1 TYPE=A ATTR=TXT:Download
WAIT SECONDS=10
Not tested of course, written from scratch, I hope I didn't make (too many) Typos, but you should spot and correct them easily, I guess... :wink:

But come back to that Thread after talking with TechSup...
(But honestly, my "pure" '.iim' Implementation is the best/simplest one, I would think..., will work in all Browsers, and you don't need any Scripting Interface...)
=> 3x mini-'EVAL()' Vars for what you want to spit out and "the Job is done", pretty simple I would think, ah-ah...! 8)

Oh Yeah, and don't worry, you already have "my Permission" to share whatever related to "Once I hear back I'll share the solution (with permission)"..., ah-ah...! :wink:
Everything you post on the Forum can always be useful for other Users in a similar Scenario/Case... 8)
(Just like the User from the Thread from 4 years ago who never bothered to follow up and share the(ir) Solution... I don't (try to) help that kind of Users again...)

>>>

You had a mini-Typo in your OP btw: "Opearting" :shock:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Trouble with VBS and running multiple scripts

Post by chivracq » Wed Jun 12, 2019 2:39 pm

Hueueueuemmm, yeah, you don't really need any (Enterprise) License for your Scenario, I would think, or maybe only a 'PE' License for v10.x for FF or CR, (for the Looping and FIO File Access for the DataSource and 'SAVEAS'), as I said, your Script can very easily be done in pure '.iim'... Your "Scenario" is very "simple", you don't need any Scripting Interface or any Scripting Language to implement it, ah-ah...! :)
Hum, there is actually a Case where the 'Scripting Interface' ('SI') might still come in handy (and therefore implementing your Scenario in '.vbs'), and that's if you (later) intend to launch your Script from a '.BAT' File or from your OS Task Scheduler, as Looping is not "really" supported for '.iim' Scripts (even if there are several (=4) Workarounds), and the Command Line Functionality for v10.0.x for FF/CR is now pretty limited otherwise and cumbersome to implement in those 2 Browsers (without the 'SI')...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
adam1337
Posts: 16
Joined: Sun Jun 09, 2019 4:12 pm

Re: Trouble with VBS and running multiple scripts

Post by adam1337 » Wed Jun 12, 2019 4:02 pm

chivracq wrote:
Tue Jun 11, 2019 4:35 pm
adam1337 wrote:
Sun Jun 09, 2019 5:01 pm
iMacros version: iMacros Browser (x86) version 12.5.503.8802
Opearting system: Windows 10 64-bit English
Browser: Internet Explorer version 11.504.17763.0 (iMacros Browser/client, not using browser extension).
Demo success: Yes
I'm using the following script to 1) login to a website, 2) loop through a 1-column csv file and use each value to make a selection from a dropdown menu, 3) submit selection, and 4) select the download link based on <a> tag content

Code: Select all

VERSION BUILD=12.5.503.8802
TAB T=1     
TAB CLOSEALLOTHERS 
' Go to login portal
URL GOTO=[login url]
' Sign-in
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:userId CONTENT=[userid]
SET !ENCRYPTION STOREDKEY
TAG POS=1 TYPE=INPUT:PASSWORD ATTR=NAME:password CONTENT=[pw]
TAG POS=1 TYPE=INPUT:SUBMIT ATTR=NAME:signin
WAIT SECONDS=10
'set csv file as datasource
SET !DATASOURCE accountlist.csv
SET !DATASOURCE_LINE {{!LOOP}}
'Set download path
ONDOWNLOAD FOLDER=E:\Folder\ FILE={{!COL1}}+document+{{!NOW:yymmdd}} WAIT=YES
SET !TIMEOUT_DOWNLOAD 20
WAIT SECONDS=3
TAG POS=1 TYPE=SELECT FORM=NAME:NoFormName ATTR=CLASS:GB01FU-BNW CONTENT=%*{{!COL1}}*
WAIT SECONDS=3
'Choose 'go' to submit selection from dropdown
TAG POS=1 TYPE=BUTTON ATTR=TXT:GO
'Click download link
TAG POS=1 TYPE=A ATTR=TXT:Download
WAIT SECONDS=10
CSV Example

Code: Select all

112314003
140234011
140074029
422407607
Since I do not want the script to loop through the login process, rather just the downloading part, I followed the docs here: https://wiki.imacros.net/Loop_after_Query_or_Login to create a VBS script which will run the scripts sequentially and loop only the desired script:

Code: Select all

Option Explicit
Dim iim1, iret

'initialize iMacros instance
set iim1 = CreateObject ("imacros")
iret = iim1.iimOpen()

'here comes the code
'query
Dim login
login = "URL GOTO=[login url]" & vbNewLine
login = login & "TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:userId CONTENT=[userid]" & vbNewLine
login = login & "SET !ENCRYPTION STOREDKEY" & vbNewLine
login = login & "TAG POS=1 TYPE=INPUT:PASSWORD ATTR=NAME:password CONTENT=[pw]" & vbNewLine
login = login & "WAIT SECONDS=2" & vbNewLine
login = login & "TAG POS=1 TYPE=INPUT:SUBMIT ATTR=NAME:signin" & vbNewLine
login = login & "WAIT SECONDS=15" & vbNewLine
iret = iim1.iimPlayCode(login)

Dim macro
macro = "SET !DATASOURCE accountlist.csv" & vbNewLine
macro = macro & "SET !DATASOURCE_LINE {{!LOOP}}" & vbNewLine
macro = macro & "ONDOWNLOAD FOLDER=E:\Folder\ FILE={{!COL1}}+Statement+{{!NOW:yymmdd}} WAIT=YES" & vbNewLine
macro = macro & "SET !TIMEOUT_DOWNLOAD 20" & vbNewLine
macro = macro & "WAIT SECONDS=3" & vbNewLine
macro = macro & "TAG POS=1 TYPE=SELECT FORM=NAME:NoFormName ATTR=CLASS:GB01FU-BNW CONTENT=%*{{!COL1}}*" & vbNewLine
macro = macro & "WAIT SECONDS=3" & vbNewLine
macro = macro & "TAG POS=1 TYPE=BUTTON ATTR=TXT:GO" & vbNewLine
macro = macro & "WAIT SECONDS=3" & vbNewLine
macro = macro & "TAG POS={{loopNumber}} TYPE=A ATTR=TXT:Download" & vbNewLine
macro = macro & "WAIT SECONDS=3" & vbNewLine

Dim recentLineNumber
recentLineNumber = 0

do while not iret < 0 
	recentLineNumber = recentLineNumber + 1
	iret = iim1.iimSet("loopNumber", Cstr(recentLineNumber))
	iret = iim1.iimPlayCode(macro)
loop

' tell user we're done
msgbox CStr((recentLineNumber-1)) & " statements saved. End."

' exit iMacros instance and quit script
iret = iim1.iimClose()
Wscript.Quit(iret)
The first macro (login) works fine when initiated through VBS script, but the second macro (macro) which loops through the CSV does not (it does not properly select the <a> tag to download). I may be able to use EVENT and CLICK to get it working through VBS, but I would rather maintain the current structure to avoid errors if multiple CSS selectors or element structure change later down the road.

When I run the second part of the script on its own in the iMacros browser using the UI "repeat" fields, it works perfectly.

Code: Select all

VERSION BUILD=12.5.503.8802
TAB T=1     
TAB CLOSEALLOTHERS 
SET !DATASOURCE accountlist.csv
SET !DATASOURCE_LINE {{!LOOP}}
'SET !PLAYBACKDELAY 0.00
'set path and filename
ONDOWNLOAD FOLDER=E:\Folder\ FILE={{!COL1}}+Statement+{{!NOW:yymmdd}} WAIT=YES
SET !TIMEOUT_DOWNLOAD 20
WAIT SECONDS=3
'select from dropdown
TAG POS=1 TYPE=SELECT FORM=NAME:NoFormName ATTR=CLASS:GB01FU-BNW CONTENT=%*{{!COL1}}*
WAIT SECONDS=3
'select 'go' to submit selection
TAG POS=1 TYPE=BUTTON ATTR=TXT:GO
'select <a> tag to download
TAG POS=1 TYPE=A ATTR=TXT:Download
WAIT SECONDS=10
I'm wondering now if VBS is optimal for this, or if I should use some other method to run the scripts separately and loop only the second one. After browsing the forum, I found this post viewtopic.php?t=24115 where chivaracq suggested .js may not be optimal either. A possible solution is provided "2- Approach Nb 2:" which may be a good solution but I can't seem to find examples which are applicable to my case. It's referring to URLs which appear to be relevant to iMacros for firefox, but I'm trying to keep everything in the iMacros browser as I'll be purchasing pro or enterprise when the trial is over.

Never touched VBS before this but I'm glad I did...that said I'm open to learning what may be necessary to accomplish this in the most efficient way.

Any guidance/suggestions/insight will be greatly appreciated.
Alright...!, I had seen your Thread when you had opened it on Sunday and had quickly had the time to approve it before going to some Festival where I didn't have any Internet for 2 days, arrggghhh...! Just back...

OK, a few Thoughts, and I hardly know anything about '.vbs', ah-ah...!

1- Hum, Interesting Thread indeed, that "older" Thread from 4 years ago now, pity the User never followed up, I guess they probably found a Solution and didn't bother to update their Thread and to share their Solution/Final Script anymore... :shock:

2- The 'Cstr' in your "iret = iim1.iimSet("loopNumber", Cstr(recentLineNumber))" is supposed to be "CStr" and not "Cstr". I'm not sure if '.vbs' is Case Sensitive (like '.js'), but that could be the Pb... :idea:

3- You can add a "PROMPT {{loopNumber}}" in your on-the-fly '.iim' Macro to check and follow that Var.

4- I'm not sure the 'CStr()' is actually really necessary, I would think that "iret = iim1.iimSet("loopNumber", recentLineNumber)" is probably already "good enough"...

5- The following Line in your '.vbs':

Code: Select all

macro = macro & "TAG POS={{loopNumber}} TYPE=A ATTR=TXT:Download" & vbNewLine
is "converted" to:

Code: Select all

'select <a> tag to download
TAG POS=1 TYPE=A ATTR=TXT:Download
... in the pure '.iim' Script where you say "When I run the second part of the script on its own in the iMacros browser using the UI "repeat" fields, it works perfectly."
Both Statements are not the same... Is the 'POS' always "1" or does it need to be incremented...? Then your '.iim' in Looping Mode should read:

Code: Select all

'select <a> tag to download
TAG POS={{!LOOP}} TYPE=A ATTR=TXT:Download
6-Hum, I have to leave now, I'll come back a bit later, but the following part can easily be done "Conditional" to be executed only on '!LOOP'=1 using 'EVAL()', to implement your Scenario in just 1 '.iim' Script, no need for '.vbs' (or '.js' or whatever0...:

Code: Select all

' Go to login portal
URL GOTO=[login url]
' Sign-in
TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:userId CONTENT=[userid]
SET !ENCRYPTION STOREDKEY
TAG POS=1 TYPE=INPUT:PASSWORD ATTR=NAME:password CONTENT=[pw]
TAG POS=1 TYPE=INPUT:SUBMIT ATTR=NAME:signin
WAIT SECONDS=10
Hope you enjoyed yourself at the festival, sounds like you did :)

The code works great, with some minor syntax tweaks as you foresaw.

I adjusted these 3 variables:

Code: Select all

'=> Conditional Vars for the Login Part:
SET URL_Login EVAL ("var d='{{!LOOP}}', us='{{URL_Site}}'; var z; if(d==1){z=us;} else{z='';}; z;")
SET Loop_1 EVAL ("var d='{{!LOOP}}'; var z; if(d==1){z=1;} else{z=0;}; z;")
SET WAIT_Login ("var d='{{!LOOP}}'; var z; if(d==1){z=10;} else{z=0;}; z;")
to this:

Code: Select all

SET URL_Login EVAL("var d='{{!LOOP}}', us='{{URL_Site}}'; var z; if(d==1){z=us;} else{z='';}; z;")
SET Loop_1 EVAL("var d='{{!LOOP}}'; var z; if(d==1){z=1;} else{z=0;}; z;")
SET WAIT_Login EVAL("var d='{{!LOOP}}'; var z; if(d==1){z=10;} else{z=0;}; z;")
to include "EVAL" for the WAIT_Login variable on the 3rd line, and to remove the spaces between "EVAL" and the opening parentheses.

I also added a WAIT statement after the {{WAIT_Login}} command because after ~10 or so tests there was 1 instance when the page did not finish loading before iMacros proceeded to the next step.

Code: Select all

WAIT SECONDS={{WAIT_Login}}
'Added WAIT 5 seconds'
WAIT SECONDS=5
I had trouble with the debug statement, so I commented it out for now. When it is included, a message appears before anything else happens. After choosing 'OK' it pauses (as instructed) and I have to resume the script with 'play' for it to continue.

This is the output (URL omitted):
debug-output.PNG
debug-output.PNG (3.88 KiB) Viewed 6156 times
To your last comment:
chivracq wrote:
Wed Jun 12, 2019 2:39 pm
Hum, there is actually a Case where the 'Scripting Interface' ('SI') might still come in handy (and therefore implementing your Scenario in '.vbs'), and that's if you (later) intend to launch your Script from a '.BAT' File or from your OS Task Scheduler, as Looping is not "really" supported for '.iim' Scripts (even if there are several (=4) Workarounds), and the Command Line Functionality for v10.0.x for FF/CR is now pretty limited otherwise and cumbersome to implement in those 2 Browsers (without the 'SI')...
My plan now is to keep using the iMacros Browser for this, rather than FF/CR. I tested on both but ran into some issues trying to select from a drop down, so I've scrapped that for now. Ultimately I want this to run monthly on it's own without requiring any user input, so I'll likely be using Windows task scheduler for this. This leads me to consider that, rather than a debug pop-up, I should implement a logging function which makes logs remotely accessible or perhaps sends them via email. This isn't a priority now, and may not even be an iMacros-specific function necessarily, but I figured I'd mention it for completeness.

Here's the complete code as it stands now, edited for syntax and debug commented out:

Code: Select all

VERSION BUILD=12.5.503.8802
SET !ERRORIGNORE YES
SET !TIMEOUT_PAGE 30
SET !TIMEOUT_STEP 0
TAB T=1     
'TAB CLOSEALLOTHERS

'Easy Access Vars:
SET URL_Site [login url]

'Login only on Loop=1:
'=> Conditional Vars for the Login Part:
'Added "EVAL" after WAIT_Login, and removed ' ' between EVAL and ( 
SET URL_Login EVAL("var d='{{!LOOP}}', us='{{URL_Site}}'; var z; if(d==1){z=us;} else{z='';}; z;")
SET Loop_1 EVAL("var d='{{!LOOP}}'; var z; if(d==1){z=1;} else{z=0;}; z;")
SET WAIT_Login EVAL("var d='{{!LOOP}}'; var z; if(d==1){z=10;} else{z=0;}; z;")

'Debug:
'SET Debug_Msg LOOP:<SP>_{{!LOOP}}_<BR><BR>URL_Site:<SP>_{{URL_Sir}}_<BR>URL_Login:<SP>_{{URL_Login}}<BR><BR>
'ADD Debug_Msg Loop_1<SP>(for<SP>POS):<SP>_{{Loop_1}}_<BR>WAIT_Login:<SP>_{{WAIT_Login}}_
'PROMPT {{Debug_Msg}}
'PAUSE

' Go to login portal
'URL GOTO=[login url]
URL GOTO={{URL_Login}}

' Sign-in:
'TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:userId CONTENT=[userid]
TAG POS={{Loop_1}} TYPE=INPUT:TEXT ATTR=NAME:userId CONTENT=[userid]
'>
SET !ENCRYPTION STOREDKEY
'TAG POS=1 TYPE=INPUT:PASSWORD ATTR=NAME:password CONTENT=[pw]
TAG POS={{Loop_1}} TYPE=INPUT:PASSWORD ATTR=NAME:password CONTENT=[pw]
'>
'TAG POS=1 TYPE=INPUT:SUBMIT ATTR=NAME:signin
TAG POS={{Loop_1}} TYPE=INPUT:SUBMIT ATTR=NAME:signin
'>
'WAIT SECONDS=10
WAIT SECONDS={{WAIT_Login}}
'Added WAIT 5 seconds'
WAIT SECONDS=5

'Looping Section:
'set csv file as datasource
SET !DATASOURCE accountlist.csv
SET !DATASOURCE_LINE {{!LOOP}}
'Set download path
ONDOWNLOAD FOLDER=E:\Folder\ FILE={{!COL1}}+document+{{!NOW:yymmdd}} WAIT=YES
SET !TIMEOUT_DOWNLOAD 20
WAIT SECONDS=3
TAG POS=1 TYPE=SELECT FORM=NAME:NoFormName ATTR=CLASS:GB01FU-BNW CONTENT=%*{{!COL1}}*
WAIT SECONDS=3
'Choose 'go' to submit selection from dropdown
TAG POS=1 TYPE=BUTTON ATTR=TXT:GO
'Click download link
TAG POS=1 TYPE=A ATTR=TXT:Download
WAIT SECONDS=10
adam1337
Posts: 16
Joined: Sun Jun 09, 2019 4:12 pm

Re: Trouble with VBS and running multiple scripts

Post by adam1337 » Wed Jun 12, 2019 4:44 pm

I ended up purchasing a license today (professional mistakenly, will be upgrading to enterprise to use vbs, for now I reverted to trial) and have shared the issue with the support team. Once I hear back I'll share the solution (with permission) or try to identify an approach that would work in this case.
Just heard back from support, they were able to fix the most recent issue I mentioned (not selecting new value from dropdown) of the original VBS script by changing one line.

The problem was this line:

Code: Select all

macro = macro & "SET !DATASOURCE_LINE {{!LOOP}}" & vbNewLine
Which I've changed to this:

Code: Select all

macro = macro & "SET !DATASOURCE_LINE {{loopNumber}}" & vbNewLine 
By changing {{!LOOP}} to the variable {{loopNumber}}, it now loops through the csv properly.

Though that is resolved, I think I will still opt for your clever all-in-one-script .iim method for the same reason you mentioned:
chivracq wrote:
Wed Jun 12, 2019 2:39 pm
my "pure" '.iim' Implementation is the best/simplest one
:wink:

Complete code with correction:

Code: Select all

Option Explicit
Dim iim1, iret

'initialize iMacros instance
set iim1 = CreateObject ("imacros")
iret = iim1.iimOpen()

'here comes the code
'query
Dim login
login = "URL GOTO=[login url]" & vbNewLine
login = login & "TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:userId CONTENT=[userid]" & vbNewLine
login = login & "SET !ENCRYPTION STOREDKEY" & vbNewLine
login = login & "TAG POS=1 TYPE=INPUT:PASSWORD ATTR=NAME:password CONTENT=[pw]" & vbNewLine
login = login & "WAIT SECONDS=2" & vbNewLine
login = login & "TAG POS=1 TYPE=INPUT:SUBMIT ATTR=NAME:signin" & vbNewLine
login = login & "WAIT SECONDS=15" & vbNewLine
iret = iim1.iimPlayCode(login)

Dim macro
macro = "SET !DATASOURCE accountlist.csv" & vbNewLine
macro = macro & "SET !DATASOURCE_LINE {{loopNumber}}" & vbNewLine
macro = macro & "ONDOWNLOAD FOLDER=E:\Folder\ FILE={{!COL1}}+Statement+{{!NOW:yymmdd}} WAIT=YES" & vbNewLine
macro = macro & "SET !TIMEOUT_DOWNLOAD 20" & vbNewLine
macro = macro & "WAIT SECONDS=3" & vbNewLine
macro = macro & "TAG POS=1 TYPE=SELECT FORM=NAME:NoFormName ATTR=CLASS:GB01FU-BNW CONTENT=%*{{!COL1}}*" & vbNewLine
macro = macro & "WAIT SECONDS=3" & vbNewLine
macro = macro & "TAG POS=1 TYPE=BUTTON ATTR=TXT:GO" & vbNewLine
macro = macro & "WAIT SECONDS=3" & vbNewLine
macro = macro & "TAG POS={{loopNumber}} TYPE=A ATTR=TXT:Download" & vbNewLine
macro = macro & "WAIT SECONDS=3" & vbNewLine

Dim recentLineNumber
recentLineNumber = 0

do while not iret < 0 
	recentLineNumber = recentLineNumber + 1
	iret = iim1.iimSet("loopNumber", Cstr(recentLineNumber))
	iret = iim1.iimPlayCode(macro)
loop

' tell user we're done
msgbox CStr((recentLineNumber-1)) & " statements saved. End."

' exit iMacros instance and quit script
iret = iim1.iimClose()
Wscript.Quit(iret)
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Trouble with VBS and running multiple scripts

Post by chivracq » Wed Jun 12, 2019 5:20 pm

adam1337 wrote:
Wed Jun 12, 2019 4:02 pm
Hope you enjoyed yourself at the festival, sounds like you did :)

The code works great, with some minor syntax tweaks as you foresaw.

I adjusted these 3 variables:

Code: Select all

'=> Conditional Vars for the Login Part:
SET URL_Login EVAL ("var d='{{!LOOP}}', us='{{URL_Site}}'; var z; if(d==1){z=us;} else{z='';}; z;")
SET Loop_1 EVAL ("var d='{{!LOOP}}'; var z; if(d==1){z=1;} else{z=0;}; z;")
SET WAIT_Login ("var d='{{!LOOP}}'; var z; if(d==1){z=10;} else{z=0;}; z;")
to this:

Code: Select all

SET URL_Login EVAL("var d='{{!LOOP}}', us='{{URL_Site}}'; var z; if(d==1){z=us;} else{z='';}; z;")
SET Loop_1 EVAL("var d='{{!LOOP}}'; var z; if(d==1){z=1;} else{z=0;}; z;")
SET WAIT_Login EVAL("var d='{{!LOOP}}'; var z; if(d==1){z=10;} else{z=0;}; z;")
to include "EVAL" for the WAIT_Login variable on the 3rd line, and to remove the spaces between "EVAL" and the opening parentheses.

I also added a WAIT statement after the {{WAIT_Login}} command because after ~10 or so tests there was 1 instance when the page did not finish loading before iMacros proceeded to the next step.

Code: Select all

WAIT SECONDS={{WAIT_Login}}
'Added WAIT 5 seconds'
WAIT SECONDS=5
I had trouble with the debug statement, so I commented it out for now. When it is included, a message appears before anything else happens. After choosing 'OK' it pauses (as instructed) and I have to resume the script with 'play' for it to continue.

This is the output (URL omitted):

debug-output.PNG

To your last comment:
chivracq wrote:
Wed Jun 12, 2019 2:39 pm
Hum, there is actually a Case where the 'Scripting Interface' ('SI') might still come in handy (and therefore implementing your Scenario in '.vbs'), and that's if you (later) intend to launch your Script from a '.BAT' File or from your OS Task Scheduler, as Looping is not "really" supported for '.iim' Scripts (even if there are several (=4) Workarounds), and the Command Line Functionality for v10.0.x for FF/CR is now pretty limited otherwise and cumbersome to implement in those 2 Browsers (without the 'SI')...
My plan now is to keep using the iMacros Browser for this, rather than FF/CR. I tested on both but ran into some issues trying to select from a drop down, so I've scrapped that for now. Ultimately I want this to run monthly on it's own without requiring any user input, so I'll likely be using Windows task scheduler for this. This leads me to consider that, rather than a debug pop-up, I should implement a logging function which makes logs remotely accessible or perhaps sends them via email. This isn't a priority now, and may not even be an iMacros-specific function necessarily, but I figured I'd mention it for completeness.

Here's the complete code as it stands now, edited for syntax and debug commented out:

Code: Select all

VERSION BUILD=12.5.503.8802
SET !ERRORIGNORE YES
SET !TIMEOUT_PAGE 30
SET !TIMEOUT_STEP 0
TAB T=1     
'TAB CLOSEALLOTHERS

'Easy Access Vars:
SET URL_Site [login url]

'Login only on Loop=1:
'=> Conditional Vars for the Login Part:
'Added "EVAL" after WAIT_Login, and removed ' ' between EVAL and ( 
SET URL_Login EVAL("var d='{{!LOOP}}', us='{{URL_Site}}'; var z; if(d==1){z=us;} else{z='';}; z;")
SET Loop_1 EVAL("var d='{{!LOOP}}'; var z; if(d==1){z=1;} else{z=0;}; z;")
SET WAIT_Login EVAL("var d='{{!LOOP}}'; var z; if(d==1){z=10;} else{z=0;}; z;")

'Debug:
'SET Debug_Msg LOOP:<SP>_{{!LOOP}}_<BR><BR>URL_Site:<SP>_{{URL_Sir}}_<BR>URL_Login:<SP>_{{URL_Login}}<BR><BR>
'ADD Debug_Msg Loop_1<SP>(for<SP>POS):<SP>_{{Loop_1}}_<BR>WAIT_Login:<SP>_{{WAIT_Login}}_
'PROMPT {{Debug_Msg}}
'PAUSE

' Go to login portal
'URL GOTO=[login url]
URL GOTO={{URL_Login}}

' Sign-in:
'TAG POS=1 TYPE=INPUT:TEXT ATTR=NAME:userId CONTENT=[userid]
TAG POS={{Loop_1}} TYPE=INPUT:TEXT ATTR=NAME:userId CONTENT=[userid]
'>
SET !ENCRYPTION STOREDKEY
'TAG POS=1 TYPE=INPUT:PASSWORD ATTR=NAME:password CONTENT=[pw]
TAG POS={{Loop_1}} TYPE=INPUT:PASSWORD ATTR=NAME:password CONTENT=[pw]
'>
'TAG POS=1 TYPE=INPUT:SUBMIT ATTR=NAME:signin
TAG POS={{Loop_1}} TYPE=INPUT:SUBMIT ATTR=NAME:signin
'>
'WAIT SECONDS=10
WAIT SECONDS={{WAIT_Login}}
'Added WAIT 5 seconds'
WAIT SECONDS=5

'Looping Section:
'set csv file as datasource
SET !DATASOURCE accountlist.csv
SET !DATASOURCE_LINE {{!LOOP}}
'Set download path
ONDOWNLOAD FOLDER=E:\Folder\ FILE={{!COL1}}+document+{{!NOW:yymmdd}} WAIT=YES
SET !TIMEOUT_DOWNLOAD 20
WAIT SECONDS=3
TAG POS=1 TYPE=SELECT FORM=NAME:NoFormName ATTR=CLASS:GB01FU-BNW CONTENT=%*{{!COL1}}*
WAIT SECONDS=3
'Choose 'go' to submit selection from dropdown
TAG POS=1 TYPE=BUTTON ATTR=TXT:GO
'Click download link
TAG POS=1 TYPE=A ATTR=TXT:Download
WAIT SECONDS=10
Oh, yep of course...!, for the few Typos in the 3 Conditional Vars with 'EVAL()'... :oops:

Yeah well for the "hard" 'WAIT=5' which now gives 15+5+5+5+...etc, you can adapt my 'WAIT_Login' to spit out "10"/"5" (then you don't need the hard one), or to "5"/"0" + the hard one if you want to get 10+5+5+5+...etc.

The Debug Section is indeed only meant for debugging your Script, by following your Vars, and once it works, to comment out the 'PROMPT' + 'PAUSE'.
But you can see how I "constructed" the 'Debug_Msg' Var with what Content I wanted to include, you can of course save the Content of that Var to some Log File (+ a Timestamp maybe, based on the '!NOW' Var like you already do in your 'ONDOWNLOAD') with a:

Code: Select all

SET !EXTRACT {{Debug_Msg}}
SAVEAS TYPE=EXTRACT etc...
But that Log File will be a "bit dirty", but on the same Principle...:

Code: Select all

SET Debug_Log_Header Timestamp:[EXTRACT]LOOP:[EXTRACT]URL_Site:[EXTRACT]URL_Login:[EXTRACT]Loop_1:<SP>(for<SP>POS):[EXTRACT]WAIT_Login:
SET Debug_Log {{!NOW:yyyymmdd_hh:nn}}[EXTRACT]_{{!LOOP}}_[EXTRACT]_{{URL_Sir}}_[EXTRACT]_{{URL_Login}}_[EXTRACT]_{{Loop_1}}_[EXTRACT]_{{WAIT_Login}}_
SET !EXTRACT {{Debug_Log_Header}}
SAVEAS TYPE=EXTRACT etc...
SET !EXTRACT {{Debug_Log}}
SAVEAS TYPE=EXTRACT etc...
And you can add/include all the Data you want to include in the Log, and with or without the '_' Delimiters I use around Vars in a 'PROMPT', it's also possible to save the Header only on the 1st Loop with a "fake" 'SAVEAS' to some Temp File for the other Loops, and that you can delete manually from time to time or even delete automatically from your Script with 'FILEDELETE'... :idea:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
adam1337
Posts: 16
Joined: Sun Jun 09, 2019 4:12 pm

Re: Trouble with VBS and running multiple scripts

Post by adam1337 » Wed Jun 12, 2019 6:34 pm

I'll certainly use that template for the debug when I set something like that up down the road.

Thanks a million for your time, fantastic code, and overall useful input you've provided me on this matter :)
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Trouble with VBS and running multiple scripts

Post by chivracq » Wed Jun 12, 2019 6:44 pm

adam1337 wrote:
Wed Jun 12, 2019 6:34 pm
I'll certainly use that template for the debug when I set something like that up down the road.

Thanks a million for your time, fantastic code, and overall useful input you've provided me on this matter :)
You're welcome, always glad to help "nice" Users, and to share some "Knowledge"... :D
And I'm pretty sure you'll be doing some "nice" Things with iMacros, ah-ah...! :wink:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
Post Reply