Workarounds for Conditional Logic in Macro Code

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
cietru141
Posts: 3
Joined: Tue Dec 17, 2013 5:41 pm

Workarounds for Conditional Logic in Macro Code

Post by cietru141 » Thu Dec 26, 2013 6:56 pm

Hi,
At the moment I am writing java code that reads from a CSV file that includes different URL's of webpages on which I want to run a macros code.The macros code obviously varies slightly according to the information in the CSV. After the CSV file is filled with the appropriate information one double click on the program I wrote, writes all the necessary iMacros code for me and saves. I then need to run it. I am very satisfied with this current framework even though it may not be the most efficient it allows me the flexibility I need.

Now in the iMacros code the java program is writing I want to extract numbers from the webpages and then I want to make decisions based on which range the numbers saved in VAR1,VAR2,VAR3 fall in.

What I've read so far seems to indicate this cannot be done using simple iMacros and any decision making needs to be done by my java code. Is this right?

If so what is the best way to work around this? Reading the data manually from the website and inserting it in the CSV is one option, but I'd like to avoid that scenario. I'd like the decision making to be done after the java code has been executed, hence at the iMacros level after the data has been extracted.

Open to any suggestions and not above hearing I'm doing it wrong!
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Decision Making using iMacros/Possible Workarounds

Post by chivracq » Mon Jan 20, 2014 4:20 pm

Late Reply and I guess/hope you'll have found a workable Solution for you in the meantime, but I didn't check the Forum that much between Xmas and NYE..., but I'll give you my Feedback anyway...:

I do use 2 Techniques in .iim Macros to force some kind of basic Conditional Processing in my Macros:
- The first one is to cleverly (sounds like I'm giving myself already some compliments...! :D ) use/misuse Relative Positioning by first tagging some informative Text Element and if that Text is found, I then R-tag the next Action Button, which means that my Macro will actually click on the Button only if the given Text is found.

Examples:

Code: Select all

TAG POS=1 TYPE=FONT ATTR=TXT:5<SP>liters<SP>/<SP>5L.
TAG POS=R1 TYPE=INPUT:CHECKBOX FORM=NAME:pig ATTR=NAME:tank CONTENT=YES

TAG POS=1 TYPE=CAPTION ATTR=TXT:Age<SP>9*<SP>%
ONDIALOG POS=1 BUTTON=OK CONTENT=
TAG POS=R-1 TYPE=A ATTR=TXT:Replace
- The other Technique I use is to apply some EVAL Statement on generally some Extracted Data but you can apply it to any Variable and to spit out a '0' or a '1' or some tailored Text that I will later on reuse for "TAG POS={{!VAR1}}" or "CONTENT={{!VAR2}}.
If !VAR1=0, then "TAG POS=0" won't do anything...

Example:

Code: Select all

'Extract Nb of Liters:
SET !EXTRACT NULL
TAG POS=1 TYPE=SPAN ATTR=TXT:Liters
TAG POS=R-1 TYPE=SPAN ATTR=TXT:* EXTRACT=TXT
'SET !VAR1 EVAL() //Spit out a 1 only for 30L...
SET !VAR1 {{!EXTRACT}}
ADD !VAR1 -29
'PROMPT {{!VAR1}}
'...
SET !TIMEOUT_STEP 1
TAG POS={{!VAR1}} TYPE=IMG ATTR=SRC:http://url.com/images/buttons/button_mix.gif
Oh!, actually, I didn't even need to use EVAL in this Example where I want to spit out a '1' only for 30 Liters but another trick with "-29"..., but you get the Principle...

But for more complex Conditional Processing, you'll need to handle the Logic from a .js Script, but I already come quite far in .iim Macros only, as I'm not a Javascript Guru, I try to avoid Javascript...
- (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: Decision Making using iMacros/Possible Workarounds

Post by chivracq » Mon Feb 17, 2014 2:22 am

Just as a Reference, related Discussion in some other Thread:
Unresponsive script warning while executing iim from js file
chivracq wrote:
sightunseen wrote:
chivracq wrote:Concerning your main Question about the unresponsive Script Warnings with iimPlay(), I haven't run into it yet, because I still only use .iim Scripts in which I have developed high Skills to until now always succeed to manage to handle the Conditional Behaviour using EVAL, Relative Positioning and very short !TIMEOUT, though converting my 10.000+ Lines of Code to smaller .iim Macros run from .js Scripts is my next big Project, but that would require a major Rewrite of the complete Workflow, so I haven't started yet... :oops:
That's very interesting. I had heard a few years ago of people using iMacros iim files with conditional behavior, and without wrapping in a js file. How are you doing it?
I already explained some of my Methods in this Thread:
Decision Making using iMacros/Possible Workarounds
I gave a few Examples, maybe not the best ones, or I have some more and maybe better, we can continue that Discussion in the other Thread if you want, in order not to "pollute" your original Question in this current Thread, or I will make it into a HowTo one day..., but basically, I play (cleverly!) with EVAL, !ERRORIGNORE, Relative Positioning based on some Text Info, and !TIMEOUT and !TIMEOUT_STEP... And I use EVAL often to spit out a "1" or a "0" to use for TAG POS=1/0, knowing that POS=0 won't do anything... or some String that I will reuse for URL or ID or CONTENT, being valid or not...
- (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...
petr
Posts: 53
Joined: Thu Jun 27, 2013 9:19 pm

Re: Decision Making using iMacros/Possible Workarounds

Post by petr » Tue Feb 18, 2014 11:42 am

This is extremely useful! If you've got other tips on this subject, I'm all eyes :))
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Decision Making using iMacros/Possible Workarounds

Post by chivracq » Tue Feb 18, 2014 12:02 pm

chivracq wrote:
petr wrote:

Code: Select all

basically, I play (cleverly!) with EVAL, !ERRORIGNORE, Relative Positioning based on some Text Info, and !TIMEOUT and !TIMEOUT_STEP... And I use EVAL often to spit out a "1" or a "0" to use for TAG POS=1/0, knowing that POS=0 won't do anything... or some String that I will reuse for URL or ID or CONTENT, being valid or not...
I'm sorry this is off topic, but I just wanted to say thanks to chivracq for this idea, it's brilliant! Now I know how to rewrite some older, awful written macros of mine. Also if you'd have some other tips, I'd really appreciate it!

Edit: OMG this is really fu***ng brilliant!!! Using this method I've rewritten 3 very long and hard to read macros and now the code is simply beautiful! Thanks again!!
Yes, this is indeed off Topic, that's why I mentioned in my previous Msg to continue the Discussion on that Subject in the other (dedicated) Thread... where I will post my Reply... But glad to hear you are already happy, Petr...! :D

Decision Making using iMacros/Possible Workarounds
>>>
petr wrote:This is extremely useful! If you've got other tips on this subject, I'm all eyes :))
OK, you've managed to locate the "dedicated" Thread...!

But anyway, glad to hear that you like my Method... And yes, I do have many other Examples as, as I mentioned before, all the Conditional Behaviour contained in my 10.000+ Lines of Code is entirely done using that Technique in .iim Code, as I don't use (yet) .js Macros...

One Example I quite like is the following:
(I need to switch on the Light in some Game between 20h-08h by pressing a Switch On/Off Button on the Page. Then I use:)

Code: Select all

SET Light EVAL("var d=\"{{!NOW:hh}}\"; if ((d>7)&&(d<20)) {var x=0;} else {var x=1;} x;")
TAG POS={{Light}} TYPE=IMG ATTR=SRC:http://website.com/images/b_light_on_off.gif
POS=0 won't click anything and POS=1 will click the Button...
Last edited by chivracq on Mon Mar 30, 2015 10:39 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...
sightunseen
Posts: 67
Joined: Fri Apr 19, 2013 4:54 am

Re: Decision Making using iMacros/Possible Workarounds

Post by sightunseen » Fri Feb 21, 2014 5:52 am

chivracq wrote:But for more complex Conditional Processing, you'll need to handle the Logic from a .js Script, but I already come quite far in .iim Macros only, as I'm not a Javascript Guru, I try to avoid Javascript...
Thanks for the great tips. Creative. I think you'd do well in javascript given your ingenuity working with iim script. The one thing that bugs me about javascript for iMacros is the apparent inability to include other js files so that I can put all my utility functions in a separate file, for example. But I'm a novice at javascript so maybe there's something I'm missing.
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Decision Making using iMacros/Possible Workarounds

Post by chivracq » Fri Feb 21, 2014 1:08 pm

sightunseen wrote:
chivracq wrote:But for more complex Conditional Processing, you'll need to handle the Logic from a .js Script, but I already come quite far in .iim Macros only, as I'm not a Javascript Guru, I try to avoid Javascript...
Thanks for the great tips. Creative. I think you'd do well in javascript given your ingenuity working with iim script. The one thing that bugs me about javascript for iMacros is the apparent inability to include other js files so that I can put all my utility functions in a separate file, for example. But I'm a novice at javascript so maybe there's something I'm missing.
Okay..., thanks for the appreciation and the compliment (more, more!!!), I will have very soon to go diving into JavaScript as, as I mentioned it earlier to you, my next big Project is indeed to (partially) convert my .iim Macros into .js Scripts as I have a lot of redundant Code and that's a pain in the @ss to maintain, each time I want to modify/improve stg... I used to be a Senior Programmer (in PowerBuilder from Sybase) and I've already experimented with most Programming Languages, so I think I will manage as well with JavaScript but it's always a bit frustrating to start all over again like a new born baby when you tackle a new Language...

About including your Functions in some external Library, there are a few Threads on the Forum about that Subject, I think I remember reading..., among others, one about using jQuerry, so if it's possible with jQuerry, it must be possible with your own Library, I would think...
- (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...
janib4all
Posts: 132
Joined: Wed Jul 21, 2010 6:44 am
Location: Karachi, Sindh, Pakistan
Contact:

Re: Decision Making using iMacros/Possible Workarounds

Post by janib4all » Mon Mar 17, 2014 9:42 am

My advise:

DO it with java scripting + iMacro. EVAL won't work all the time..
Hire the BoT-fReeak!
botspecialist.blogspot.com
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Decision Making using iMacros/Possible Workarounds

Post by chivracq » Fri Jul 25, 2014 4:13 pm

As I'm often referring to this current Thread for Users starting new Threads where these Techniques can be used, I'm adding a Section (that I will keep maintaining) where I mention other Threads that can serve as extra Examples...

- Any way to "WAIT UNTIL IP CHANGE" OR seomthing? (2014/Jan) About a "Conditional WAIT".
- Macro last line is reached (csv) (2014/Feb)
- Help on TAG or SEARCH (2016/Jan) With a Macro in pure '.iim' to take Decisions on some Bidding Site using 'EVAL()', Relative Positioning and 'MacroError()' + contains a Workaround for '!ENDOFPAGE' which is not implemented in iMacros FF.
- Re: PROMPT Messagebox - Yes - No - Cancel (end) (2016/Jan+Novb) About a "Conditional PROMPT" in pure '.iim' for iMacros for FF (+ Workaround(s) for 'javascript:alert()' Bug on FF).
- Re: Help evaluating something on a webpage (2014/Jan) Thread Title a bit vague but it's about a "Conditional SOUND".
- How to use EVAL to Stop the Macro when there is no Next? (Octb 2017) About how a "cumbersome" Implementation in '.js' with 3 or 4 different '.iim' Scripts can be implemented with only 1 single '.iim' Script, with Technique about "muting" a complete part of the Script after 'LOOP=1' + Conditional '!TIMEOUT_STEP' + Debug Technique and Use of 'PROMPT'.

>>>

+Adding a direct Link to this (original) Current Thread as it's been included (copied) to the 'Howto' Sub-Forum by TechSupport as a useful Thread, for me to be able to locate a bit easily the original Thread when I want to edit it to add some other Links to interesting Threads:
- Decision Making using iMacros/Possible Workarounds
(Hum, no wonder I was having some difficulties to locate the original Thread, I had not realized the Thread Title had been modified, ah-ah...!)
Last edited by chivracq on Sat Oct 07, 2017 9:58 am, edited 3 times 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...
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Decision Making using iMacros/Possible Workarounds

Post by chivracq » Thu Sep 15, 2016 4:26 pm

Grace wrote:
petr wrote:This is extremely useful! If you've got other tips on this subject, I'm all eyes :))
I agree with petr, i know this is a dead thread (OLD thread) but the tips mentioned here are gold, Thanks OP
Thread is not "dead", I still maintain it from time to time (well, I'm a bit behind, oops...!) the List of relevant/similar Threads that can be used as Examples... 8)

Keywords (in different Combinations) that can be used to search the Forum for such Threads:
chivracq + Conditional + [Behaviour (UK Spelling!) / Logic / WAIT / Refresh / Sound / PROMPT] + spit out + EVAL + split + (Double) Relative Positioning...

(And the Tips and Techniques don't come from OP but from me...)
Last edited by chivracq on Thu Mar 12, 2020 8:56 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...
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Workarounds for Conditional Logic in Macro Code

Post by chivracq » Sun Feb 26, 2017 6:55 pm

Sharoun wrote:, SOrry my bad chivracq, good on ya mate I agree with petr, i know this is a dead thread (OLD thread) but the tips mentioned here are gold
Thread is not dead, I keep adding from time to time relevant Threads with "good Examples" to my earlier Post in this current Thread and I mentioned in my last Post all Keywords that can be used to find all more recent Threads about "Conditional whatever...!" on the Forum:
chivracq wrote:Keywords (in different Combinations) that can be used to search the Forum for such Threads:
chivracq + Conditional + [Behaviour (UK Spelling!) / Logic / WAIT / Refresh / Sound / PROMPT] + spit out + EVAL + split + (Double) Relative Positioning...
Hum, Quote from previous User was from a fake User who only registered on the Forum to be able to post some Spam... Post and User will be deleted, one day...!
Last edited by chivracq on Sat Oct 07, 2017 9:49 am, 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...
Post Reply