How to enable loging ?

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
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
mybox65
Posts: 7
Joined: Tue Dec 02, 2014 5:22 pm

How to enable loging ?

Post by mybox65 » Tue Dec 02, 2014 5:32 pm

for example , The {{!COL1}} store a list of IP addresses that we want to login one by one, if we can not login or can not reach some of ip addresses during the iMacros runing, I wish I can log all unlogin and unreachable ip address in another .csv file.


SET !DATASOURCE example.csv
SET !DATASOURCE_LINE {{!LOOP}}
URL GOTO={{!COL1}}
TAG POS=1 TYPE=INPUT:TEXT FORM=form1 ATTR=NAME:first_name CONTENT={{!COL2}}
Snayler
Posts: 12
Joined: Wed Mar 26, 2014 2:12 pm

Re: How to enable loging ?

Post by Snayler » Wed Dec 03, 2014 10:42 am

This should be relatively easy to do with javascript and imacros. In a JS file, you only have to check for the error code related to the loading of pages (-802 == Timeout error (failed to load web page) ). This will tell you which addresses are unreachable, you can even make the script test all the addresses multiple times to be sure. As for addresses to which you can't login to, you would have to include in your code some way to detect the failed login (usually an extract of the error message is enough).

Some sample code:

Code: Select all

//check if page didn't load
code= "CODE:URL GOTO=www.google.com"+"\n"
if(iimPlay(code) == -802){
    //iMacros code to save the address into another csv file
}

//check if login successful
code = "CODE:TAG POS=1 TYPE=SPAN ATTR=ID:login_failed EXTRACT=TXT"
iimPlay(code)
//verify if EXTRACT is different from "#EANF#" (extract value when element with specified attribute was not found).
//If it is different from "#EANF#", it means the error message was found.
if(iimGetExtract()!=#EANF#){
    //iMacros code to save the address into another csv file
}
chivracq
Posts: 9377
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How to enable loging ?

Post by chivracq » Thu Dec 04, 2014 2:50 am

mybox65 wrote:for example , The {{!COL1}} store a list of IP addresses that we want to login one by one, if we can not login or can not reach some of ip addresses during the iMacros runing, I wish I can log all unlogin and unreachable ip address in another .csv file.

SET !DATASOURCE example.csv
SET !DATASOURCE_LINE {{!LOOP}}
URL GOTO={{!COL1}}
TAG POS=1 TYPE=INPUT:TEXT FORM=form1 ATTR=NAME:first_name CONTENT={{!COL2}}
CIM...! :mrgreen:
- (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...
mybox65
Posts: 7
Joined: Tue Dec 02, 2014 5:22 pm

Re: How to enable loging ?

Post by mybox65 » Fri Dec 05, 2014 6:53 pm

Thanks a lot for Snayler and chivracq !! Actually I tried to do a lot of reach and tried to make it by myself ,but I still can not make it work.
I put my whole entire IMacros script below, Could you please give me a hand to add the log function in it ? Besides this , I know some of VBS language, is it possible using the VBS to instead of Java Script ? and where I can lean the programming of IMacros (jvs or vbs or vba) ? I do appreciate a lot for your kindly help.


***********Firefox v33.1 , win7 64bit ; iMacros v10.2*************
VERSION BUILD=8871104 RECORDER=FX
TAB T=1
SET !ERRORIGNORE YES
CMDLINE !DATASOURCE UPStest1.csv
SET !DATASOURCE_COLUMNS 3
SET !LOOP 2
SET !DATASOURCE_LINE {{!LOOP}}
URL GOTO={{!COL1}}
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:HashForm1 ATTR=NAME:login_username CONTENT={{!COL2}}
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=NAME:HashForm1 ATTR=NAME:login_password CONTENT={{!COL3}}
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:HashForm1 ATTR=NAME:submit
TAG POS=1 TYPE=A ATTR=TXT:UPS
TAG POS=1 TYPE=A ATTR=TXT:Scheduling
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:HashForm1 ATTR=NAME:submit
TAG POS=1 TYPE=SELECT FORM=NAME:HashForm1 ATTR=NAME:UPSActionMonth CONTENT=$12
TAG POS=1 TYPE=SELECT FORM=NAME:HashForm1 ATTR=NAME:UPSActionMonthDay CONTENT=$31
TAG POS=1 TYPE=SELECT FORM=NAME:HashForm1 ATTR=NAME:UPSActionHour CONTENT=$22
TAG POS=3 TYPE=INPUT:RADIO FORM=NAME:HashForm1 ATTR=NAME:UPSActionTurnOn
TAG POS=1 TYPE=SELECT FORM=NAME:HashForm1 ATTR=NAME:UPSActionEndMonth CONTENT=$12
TAG POS=1 TYPE=SELECT FORM=NAME:HashForm1 ATTR=NAME:UPSActionEndMonthDay CONTENT=$31
TAG POS=1 TYPE=SELECT FORM=NAME:HashForm1 ATTR=NAME:UPSActionEndHour CONTENT=$23
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:HashForm1 ATTR=NAME:submit
WAIT SECONDS=5
TAG POS=1 TYPE=A ATTR=TXT:Log<SP>Off



***
UPStest1.csv is as below:
IP address,USER,PASS
10.10.18.106,apc1,xxxx1
10.10.16.29,apc2,xxxx2
chivracq
Posts: 9377
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How to enable loging ?

Post by chivracq » Sat Dec 06, 2014 2:07 pm

mybox65 wrote:Thanks a lot for Snayler and chivracq !! Actually I tried to do a lot of reach and tried to make it by myself ,but I still can not make it work.
I put my whole entire IMacros script below, Could you please give me a hand to add the log function in it ? Besides this , I know some of VBS language, is it possible using the VBS to instead of Java Script ? and where I can lean the programming of IMacros (jvs or vbs or vba) ? I do appreciate a lot for your kindly help.

***********Firefox v33.1 , win7 64bit ; iMacros v10.2*************

Code: Select all

VERSION BUILD=8871104 RECORDER=FX
TAB T=1
SET !ERRORIGNORE YES
CMDLINE !DATASOURCE  UPStest1.csv
SET !DATASOURCE_COLUMNS 3
SET !LOOP 2
SET !DATASOURCE_LINE {{!LOOP}}
URL GOTO={{!COL1}}
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:HashForm1 ATTR=NAME:login_username CONTENT={{!COL2}}
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=NAME:HashForm1 ATTR=NAME:login_password CONTENT={{!COL3}}
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:HashForm1 ATTR=NAME:submit
TAG POS=1 TYPE=A ATTR=TXT:UPS
TAG POS=1 TYPE=A ATTR=TXT:Scheduling
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:HashForm1 ATTR=NAME:submit
TAG POS=1 TYPE=SELECT FORM=NAME:HashForm1 ATTR=NAME:UPSActionMonth CONTENT=$12
TAG POS=1 TYPE=SELECT FORM=NAME:HashForm1 ATTR=NAME:UPSActionMonthDay CONTENT=$31
TAG POS=1 TYPE=SELECT FORM=NAME:HashForm1 ATTR=NAME:UPSActionHour CONTENT=$22
TAG POS=3 TYPE=INPUT:RADIO FORM=NAME:HashForm1 ATTR=NAME:UPSActionTurnOn
TAG POS=1 TYPE=SELECT FORM=NAME:HashForm1 ATTR=NAME:UPSActionEndMonth CONTENT=$12
TAG POS=1 TYPE=SELECT FORM=NAME:HashForm1 ATTR=NAME:UPSActionEndMonthDay CONTENT=$31
TAG POS=1 TYPE=SELECT FORM=NAME:HashForm1 ATTR=NAME:UPSActionEndHour CONTENT=$23
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:HashForm1 ATTR=NAME:submit
WAIT SECONDS=5
TAG POS=1 TYPE=A ATTR=TXT:Log<SP>Off
***
UPStest1.csv is as below:
IP address,USER,PASS
10.10.18.106,apc1,xxxx1
10.10.16.29,apc2,xxxx2
OK, from your Script, I can deduct that all IP-Addresses after successful Login will load a similar Page where your Script first clicks on a 'UPS' Link, then you can simply check if this Link is present on the Page...:

Code: Select all

VERSION BUILD=8871104 RECORDER=FX
TAB T=1
SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 1

CMDLINE !DATASOURCE  UPStest1.csv
SET !DATASOURCE_COLUMNS 3
SET !LOOP 2
SET !DATASOURCE_LINE {{!LOOP}}

URL GOTO={{!COL1}}
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:HashForm1 ATTR=NAME:login_username CONTENT={{!COL2}}
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=NAME:HashForm1 ATTR=NAME:login_password CONTENT={{!COL3}}
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:HashForm1 ATTR=NAME:submit

'Logging FAILED Logins:
TAG POS=1 TYPE=A ATTR=TXT:UPS EXTRACT=TXT
SET Log_UPS_Failed EVAL("var s='{{!EXTRACT}}'; var x; if(s='UPS') {x='';} else {x='UPS_Login_FAILED.log';} x;")
SET !EXTRACT {{!Now:yyyymmdd_hhnnss}}
ADD !EXTRACT {{!COL1}}
ADD !EXTRACT {{!COL2}}
ADD !EXTRACT "Login FAILED"
SAVEAS TYPE=EXTRACT FOLDER=* FILE={{Log_UPS_Failed}}

'Shorten '!TIMEOUT_STEP' to "0" here if many FAILED are expected...:
'SET !TIMEOUT_STEP 0
TAG POS=1 TYPE=A ATTR=TXT:UPS
TAG POS=1 TYPE=A ATTR=TXT:Scheduling
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:HashForm1 ATTR=NAME:submit
TAG POS=1 TYPE=SELECT FORM=NAME:HashForm1 ATTR=NAME:UPSActionMonth CONTENT=$12
TAG POS=1 TYPE=SELECT FORM=NAME:HashForm1 ATTR=NAME:UPSActionMonthDay CONTENT=$31
TAG POS=1 TYPE=SELECT FORM=NAME:HashForm1 ATTR=NAME:UPSActionHour CONTENT=$22
TAG POS=3 TYPE=INPUT:RADIO FORM=NAME:HashForm1 ATTR=NAME:UPSActionTurnOn
TAG POS=1 TYPE=SELECT FORM=NAME:HashForm1 ATTR=NAME:UPSActionEndMonth CONTENT=$12
TAG POS=1 TYPE=SELECT FORM=NAME:HashForm1 ATTR=NAME:UPSActionEndMonthDay CONTENT=$31
TAG POS=1 TYPE=SELECT FORM=NAME:HashForm1 ATTR=NAME:UPSActionEndHour CONTENT=$23
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:HashForm1 ATTR=NAME:submit
WAIT SECONDS=5
TAG POS=1 TYPE=A ATTR=TXT:Log<SP>Off
(Not tested...)

EDIT: if(s='UPS') {x='';} => if(s=='UPS') {x='';}
Last edited by chivracq on Mon Dec 08, 2014 5:21 pm, edited 1 time in total.
- (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...
mybox65
Posts: 7
Joined: Tue Dec 02, 2014 5:22 pm

Re: How to enable loging ?

Post by mybox65 » Mon Dec 08, 2014 5:01 pm

OK, from your Script, I can deduct that all IP-Addresses after successful Login will load a similar Page where your Script first clicks on a 'UPS' Link, then you can simply check if this Link is present on the Page...:

Code: Select all

VERSION BUILD=8871104 RECORDER=FX
TAB T=1
SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 1

CMDLINE !DATASOURCE  UPStest1.csv
SET !DATASOURCE_COLUMNS 3
SET !LOOP 2
SET !DATASOURCE_LINE {{!LOOP}}

URL GOTO={{!COL1}}
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:HashForm1 ATTR=NAME:login_username CONTENT={{!COL2}}
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=NAME:HashForm1 ATTR=NAME:login_password CONTENT={{!COL3}}
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:HashForm1 ATTR=NAME:submit

'Logging FAILED Logins:
TAG POS=1 TYPE=A ATTR=TXT:UPS EXTRACT=TXT
SET Log_UPS_Failed EVAL("var s='{{!EXTRACT}}'; var x; if(s='UPS') {x='';} else {x='UPS_Login_FAILED.log';} x;")
SET !EXTRACT {{!Now:yyyymmdd_hhnnss}}
ADD !EXTRACT {{!COL1}}
ADD !EXTRACT {{!COL2}}
ADD !EXTRACT "Login FAILED"
SAVEAS TYPE=EXTRACT FOLDER=* FILE={{Log_UPS_Failed}}

'Shorten '!TIMEOUT_STEP' to "0" here if many FAILED are expected...:
'SET !TIMEOUT_STEP 0
TAG POS=1 TYPE=A ATTR=TXT:UPS
TAG POS=1 TYPE=A ATTR=TXT:Scheduling
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:HashForm1 ATTR=NAME:submit
TAG POS=1 TYPE=SELECT FORM=NAME:HashForm1 ATTR=NAME:UPSActionMonth CONTENT=$12
TAG POS=1 TYPE=SELECT FORM=NAME:HashForm1 ATTR=NAME:UPSActionMonthDay CONTENT=$31
TAG POS=1 TYPE=SELECT FORM=NAME:HashForm1 ATTR=NAME:UPSActionHour CONTENT=$22
TAG POS=3 TYPE=INPUT:RADIO FORM=NAME:HashForm1 ATTR=NAME:UPSActionTurnOn
TAG POS=1 TYPE=SELECT FORM=NAME:HashForm1 ATTR=NAME:UPSActionEndMonth CONTENT=$12
TAG POS=1 TYPE=SELECT FORM=NAME:HashForm1 ATTR=NAME:UPSActionEndMonthDay CONTENT=$31
TAG POS=1 TYPE=SELECT FORM=NAME:HashForm1 ATTR=NAME:UPSActionEndHour CONTENT=$23
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:HashForm1 ATTR=NAME:submit
WAIT SECONDS=5
TAG POS=1 TYPE=A ATTR=TXT:Log<SP>Off
(Not tested...)

Much appreciate your help ! Actually I did some testing, but it sounds the script can not create any log file (Log_UPS_Failed). I tried to give it some unreachable ip addresses and some reachable IP addresses with invalid account name or bad password, but none of them were logged to the Log_UPS_Failed file, I even can not find the file of the Log_UPS_Failed .

I also tried to add an extra line “PROMPT See<SP>{{Log_UPS_Failed}}” before "SAVEAS TYPE=EXTRACT FOLDER=* FILE={{Log_UPS_Failed}}" , but nothing appeared.
chivracq
Posts: 9377
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How to enable loging ?

Post by chivracq » Mon Dec 08, 2014 5:19 pm

mybox65 wrote:Much appreciate your help ! Actually I did some testing, but it sounds the script can not create any log file (Log_UPS_Failed). I tried to give it some unreachable ip addresses and some reachable IP addresses with invalid account name or bad password, but none of them were logged to the Log_UPS_Failed file, I even can not find the file of the Log_UPS_Failed .

I also tried to add an extra line “PROMPT See<SP>{{Log_UPS_Failed}}” before "SAVEAS TYPE=EXTRACT FOLDER=* FILE={{Log_UPS_Failed}}" , but nothing appeared.
Yep indeed, mini-Mistake: if(s='UPS') => if(s=='UPS')
Not tested again..., but it should work, I use a very similar Code in one of my Scripts, I've corrected in my previous Post...
- (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...
mybox65
Posts: 7
Joined: Tue Dec 02, 2014 5:22 pm

Re: How to enable loging ?

Post by mybox65 » Mon Dec 08, 2014 6:24 pm

chivracq wrote:
mybox65 wrote:Much appreciate your help ! Actually I did some testing, but it sounds the script can not create any log file (Log_UPS_Failed). I tried to give it some unreachable ip addresses and some reachable IP addresses with invalid account name or bad password, but none of them were logged to the Log_UPS_Failed file, I even can not find the file of the Log_UPS_Failed .

I also tried to add an extra line “PROMPT See<SP>{{Log_UPS_Failed}}” before "SAVEAS TYPE=EXTRACT FOLDER=* FILE={{Log_UPS_Failed}}" , but nothing appeared.
Yep indeed, mini-Mistake: if(s='UPS') => if(s=='UPS')
Not tested again..., but it should work, I use a very similar Code in one of my Scripts, I've corrected in my previous Post...

Yes, it works. Thanks a lot for your help. I understand most of lines of the script , except this "TAG POS=1 TYPE=A ATTR=TXT:UPS EXTRACT=TXT" , Why do you use ATTR=Txt:UPS and EXTRACT =TXT ? What does it mean of the "UPS" in the line ? Thanks again for your help.
chivracq
Posts: 9377
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How to enable loging ?

Post by chivracq » Mon Dec 08, 2014 6:53 pm

mybox65 wrote:
chivracq wrote:
mybox65 wrote:Much appreciate your help ! Actually I did some testing, but it sounds the script can not create any log file (Log_UPS_Failed). I tried to give it some unreachable ip addresses and some reachable IP addresses with invalid account name or bad password, but none of them were logged to the Log_UPS_Failed file, I even can not find the file of the Log_UPS_Failed .

I also tried to add an extra line “PROMPT See<SP>{{Log_UPS_Failed}}” before "SAVEAS TYPE=EXTRACT FOLDER=* FILE={{Log_UPS_Failed}}" , but nothing appeared.
Yep indeed, mini-Mistake: if(s='UPS') => if(s=='UPS')
Not tested again..., but it should work, I use a very similar Code in one of my Scripts, I've corrected in my previous Post...
Yes, it works. Thanks a lot for your help. I understand most of lines of the script , except this "TAG POS=1 TYPE=A ATTR=TXT:UPS EXTRACT=TXT" , Why do you use ATTR=Txt:UPS and EXTRACT =TXT ? What does it mean of the "UPS" in the line ? Thanks again for your help.
Oh..., good (that it works...!), there is always a risk without the URL or an HTML Saveas of the Page to make a Typo as I cannot really test against the real Page...

What my Script (and this Line) does, is after a successful Login, the first thing you do is clicking on a 'UPS' Link, I then check to see if that Link is present on the Page by reusing the exact Statement that you recorded and adding the "EXTRACT=TXT" to extract "UPS" if the Link is present on the Page (or "#EANF#" if it's not there for any reason)...

Check the Wiki Page for the 'TAG' Command and the 'EXTRACT' Parameter for more explanation... (and for other Uses...)
- (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...
Post Reply