Trying If else condition in EVAL in imacros gives error - if-statement

This is the link from where I m extracting data
TAG POS=1 TYPE=DIV ATTR=CLASS:sLB&&TXT:* EXTRACT=TXT
SET pqr {{!EXTRACT}}
SET !EXTRACT NULL
TAG POS=R1 TYPE=INPUT ATTR=TYPE:HIDDEN&&TXT:* EXTRACT=TXT
SET abc {{!EXTRACT}}
SET !EXTRACT NULL
TAG POS=R1 TYPE=INPUT ATTR=TYPE:HIDDEN&&TXT:* EXTRACT=TXT
SET def {{!EXTRACT}}
SET !EXTRACT NULL
PROMPT "{{abc}} BHK {{def}}"
SET VAR7 EVAL("if (\"{{!abc}}\" == ' ') PROMPT "{{abc}} {{def}}"; else \"PROMPT "{{abc}} BHK {{def}}\";")
PROMPT {{VAR7}}
Here I'm checking the condition if the value of the variable abc is null or blank, then print data of two variable i.e abc and def else print data of abc and def concatenated with BHK in between the both.
But this gives me error
MacroSyntaxError: wrong format of SET command, line 71 (Error code: -910)
Any suggestion where I'm going wrong.
Any help would be much appreciated. Thanks

Let me see if I understand your question...
If variable abc is null or blank,
then return abc and def (why bother returning abc if it's blank/null?)
else return abc + "BHK" + def
Since I don't really understand exactly what you're extracting even though you provided a link, I created a test case below with the answer:
'Set test values
SET abc "100"
SET def "Apartment"
'Evaluation below, will abc = ' '?
SET VAR7 EVAL("('{{abc}}'==' ')?\"{{abc}} {{def}}\" : \"{{abc}} BHK {{def}}\";")
'return results of evaluation
PROMPT {{VAR7}}
'test abc with blank value
SET abc " "
SET VAR7 EVAL("('{{abc}}'==' ')?\"{{abc}} {{def}}\" : \"{{abc}} BHK {{def}}\";")
'return results of evaluation
PROMPT {{VAR7}}
Remember, you can't use Javascript to control flow/logic for Imacros. It looked like you were trying to create Imacro commands via javascript. If this answer helped, please mark as such. Thanks!

Related

iMacros: how to extract once every few loops

my script extract once every 60 loops, 1,60,120,180 .. etc
TAG POS=1, so I use made this with EVAL.
but my problem is that {{Datastart}} is empty when no value to extract
My question is how to make {{Datastart}} EVAL to work like {{1datastart}} ?
I mean to remain the first extract value from loop1 during the next 59 loop and to extract the value again at loop 61.
SET !ERRORIGNORE YES
SET 1datastart EVAL("var n='{{!LOOP}}'; var z; if((n%60)==1){z=\"1\";} else{z=0;}; z;")
TAG POS={{1datastart}} TYPE=DIV ATTR=CLASS:"*cell-body tablecell-date sortable column-sorted*"&&TXT:*,* EXTRACT=TXT
SET datastart EVAL("'{{!EXTRACT}}'.replace(/(Scheduled|Published)/g, '').trim();")
Prompt {{datastart}}
I am using (FCI): iMacros for CR v10.1.1 'PE', CR v105.0.5195.102 (_x64), Win10_x64. ('CR' = 'Chrome' / 'PE' = 'Personal Edition')

iMacros - How to Extract the first 100 Characters from a `TAG CONTENT`?

I am using this code in iMacros to extract only the first 100 characters from TAG CONTENT and it's working in 80% of the cases, but sometimes iMacros displays an error message:
"TypeError: Cannot read properties of null (reading 'join'), line: 27"
(Line 27 in iMacros Code is where the code is executed.)
=> My question:
Is there another way to do this, another Regex code, or did I do something wrong with the script below?
TAG POS=1 TYPE=DIV ATTR=ID:title EXTRACT=TXT
SET titlu100 EVAL("var x=\"{{!EXTRACT}}\"; x=x.match(/^.{100}/).join(''); x;")
I am using (FCI):
iMacros for CR v10.1.1 'PE', CR v105.0.5195.102 (_x64), Win10_x64.
('CR' = 'Chrome' / 'PE' = 'Personal Edition')
Meanwhile I found another way to extract first 100 characters
SET titlu100 EVAL("\"{{!EXTRACT}}\".substr(0,100);")

imacros take from multi files in DATASOURCE loop

I have imacros firefox Add-ons that takes data from one csv file. But i need to tell imacros to take data from multi files as loop
here my script is take from 1.csv
but I've 2.csv & 3.csv & 4.csv and more.. i need it to take from them as loop like if i run play imacros will take data from 1.csv once they finish start again but from 2.csv ..etc like that.. with the same rule for all.. also the files all are the same columns same data but cannot merge them as one file.csv
SET !DATASOURCE /Users/almishal/Desktop/imacros/new/1.csv
SET !DATASOURCE_COLUMNS 18
SET !LOOP 1
SET !DATASOURCE_LINE {{!LOOP}}
TAB CLOSEALLOTHERS
TAG POS=1 TYPE=IMG ATTR=SRC:http://www.example.com/vb/sty1/buttons/newthread.gif
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:vbform ATTR=NAME:subject CONTENT={{!COL2}}
SET !VAR1 EVAL("'{{!COL4}}'.replace(/^965/gi,"")")
SET PRICE {{!COL5}}
SET !VAR3 EVAL("'price:<SP>{{PRICE}}<SP>dollar'.replace(/price:<SP>0+<SP>dollar/,"")")
TAG POS=1 TYPE=TEXTAREA FORM=NAME:vbform ATTR=ID:vB_Editor_001_textarea CONTENT=[CENTER]{{!COL3}}<BR>{{!VAR3}}<BR><SP>my<SP>number<SP>{{!VAR1}}<SP><BR><BR>{{!VAR2}}<BR>[/CENTER]
TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:vbform ATTR=ID:vB_Editor_001_save
TAG POS=1 TYPE=AREA ATTR=HREF:http://www.example.com/vb/index.php
ONDIALOG POS=1 BUTTON=OK CONTENT=
TAG POS=1 TYPE=A ATTR=TXT:log<SP>out
You can get the most elegant solution with the help of the JavaScript Scripting Interface. But here I suggest a one using only ‘iim’s. So, create e.g. ‘macro1.iim’ for ‘1.csv’, ‘macro2.iim’ for ‘2.csv’ etc. The code of the ‘macro1.iim’ will be as follows:
' number of lines in csv-files
SET linesInFile 1
SET !LOOP EVAL(2-{{linesInFile}})
SET !DATASOURCE /Users/almishal/Desktop/imacros/new/1.csv
SET !DATASOURCE_LINE EVAL({{!LOOP}}+{{linesInFile}}-1)
TAB CLOSEALLOTHERS
' ... (your code here)
' next macro to play
SET next "macro2"
SET S EVAL("('{{!LOOP}}' == 1) ? 'imacros://run/?m={{next}}.iim' : 'javascript:undefined;';")
URL GOTO={{S}}
I believe that you’ve caught the idea and will make necessary corrections to ‘macro2.iim’ etc. (There won’t be a ‘next macro to play’ block in the last macro.) In order to play this chain you should run only ‘macro1.iim’ in usual (NOT loop) mode. Also note that I supposed that all macros are in the root of the default ‘iMacros’ folder for them.

iMacros if/else statement how to?

I'm attempting to pull some data from a webpage. I'm running into trouble with an extra line of data that occurs in some situations.
Here is a block of my code:
VERSION BUILD=10.4.28.1074
TAB T=1
TAG POS=114 TYPE=TR ATTR=* EXTRACT=TXT
SET !VAR1 {{!EXTRACT}}
SET !EXTRACT NULL
TAG POS=115 TYPE=TR ATTR=* EXTRACT=TXT
SET !VAR2 {{!EXTRACT}}
SET !EXTRACT NULL
TAG POS=116 TYPE=TR ATTR=* EXTRACT=TXT
ADD !EXTRACT {{!VAR1}}
ADD !EXTRACT {{!VAR2}}
SAVEAS TYPE=EXTRACT FOLDER=\\admin\Documents\iMacros FILE=extracttest2.csv
You'll notice this code has tag pos 114,115, and 116. However, sometimes I will only need to extract 114 and 115.
POS 114 starts with either "Owner:" or "Owners:". If "Owner:" then I only need to extract 114 and 115. If "Owners:" I need to extract 114, 115, and 116.
Is there a way to make an if/else statement or other type of rule that says if 114 contains the word "Owner" only POS 114 and 115 will be extracted. And if 114 contains the word "Owners" POS 114, 115 and 116 will be extracted?
Thanks in advance for any advice.
Here is one of the variants without applying the Scripting Interface. Instead of the line TAG POS=116 TYPE=TR ATTR=* EXTRACT=TXT add this block:
SET pos116 EVAL("('{{!VAR1}}'.match(/Owners:/)) ? 116 : 99999;")
SET !ERRORIGNORE YES
SET !TIMEOUT_STEP 0
TAG POS={{pos116}} TYPE=TR ATTR=* EXTRACT=TXT
SET !ERRORIGNORE NO
SET !TIMEOUT_STEP 6
SET !EXTRACT EVAL("('{{!EXTRACT}}' == '#EANF#') ? '' : '{{!EXTRACT}}';")
Note: I suppose that on the webpage there’s no element with TAG POS=99999 TYPE=TR ATTR=* .
Try something like this using the EVAL command so you can use if/else conditions:
SET NEWVAR EVAL("var s=\"{{!VAR1}}\"; if(!s.match(/owners/g)) {s=\"!VAR1\";} else {s=\"!VAR2\";")
Read more at the iMacros wiki

how to edit the string form csv in macro script

I have csv file, which is called containg list of urls and looks like this :
My script will take the screenshots for all these urls.
My code looks like this:
VERSION BUILD=8871104 RECORDER=FX
TAB T=1
TAB CLOSEALLOTHERS
SET !ERRORIGNORE YES
SET !TIMEOUT_PAGE 120
SET !DATASOURCE W:\url-list-with-change-in-page-size.csv
SET !DATASOURCE_COLUMNS 1
SET !DATASOURCE_LINE {{!LOOP}}
URL GOTO={{!COL1}}
WAIT SECONDS=2
SET VAR1 {{!COL1}}
SET VAR2 EVAL("var s=\"{{VAR1}}\"; s.replace("http://",""); ")
SCREENSHOT TYPE=Page FOLDER=C:\Users\iMacros\Downloads FILE={{VAR2}}
This gives me an error wrong format of SET command, line 13 (Error code: 910)
So basically,
I have
{{COL1}} = http://www.webcentral.com.au/marketing/search-engine-optimisation
and i want
{{$VAR1}} = www.webcentral.com.au_marketing_search-engine-optimisation
With the help of EVAL() i want to first remove http:// and then replace / with _.
Any suggestions please.
Thanks
SET VAR2 EVAL("'{{VAR1}}'.replace('http://','').replace(/\\//g,'_');")
There are two ways to do this. Easiest would be to add one more column in your CSV with the name you want for that url. That way you dont have you manipulate the data. If you must use EVAL, you need to escape certain characters.
This works for me:
SET !VAR1 "http://stackoverflow.com/questions/28024675/how-to-edit-the-
string-form-csv-in-macro-script/28063429#28063429"
PROMPT {{!VAR1}}
SET !VAR2 EVAL("var x=\"{{!var1}}\"; var y=x.replace(\"http://\",\"\"); y;")
PROMPT {{!VAR2}}