Workarounds for Conditional Logic in Macro Code
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
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
Workarounds for Conditional Logic in Macro Code
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!
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!
Re: Decision Making using iMacros/Possible Workarounds
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...! ) 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:
- 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:
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...
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...! ) 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
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
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...
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
Re: Decision Making using iMacros/Possible Workarounds
Just as a Reference, related Discussion in some other Thread:
Unresponsive script warning while executing iim from js file
Unresponsive script warning while executing iim from js file
chivracq wrote:I already explained some of my Methods in this Thread:sightunseen wrote: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?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...
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...
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
Re: Decision Making using iMacros/Possible Workarounds
This is extremely useful! If you've got other tips on this subject, I'm all eyes )
Re: Decision Making using iMacros/Possible Workarounds
>>>chivracq wrote: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...!petr wrote: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!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...
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!!
Decision Making using iMacros/Possible Workarounds
OK, you've managed to locate the "dedicated" Thread...!petr wrote:This is extremely useful! If you've got other tips on this subject, I'm all eyes )
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
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...
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
-
- Posts: 67
- Joined: Fri Apr 19, 2013 4:54 am
Re: Decision Making using iMacros/Possible Workarounds
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 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...
Re: Decision Making using iMacros/Possible Workarounds
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...sightunseen wrote: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 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...
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...
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
Re: Decision Making using iMacros/Possible Workarounds
My advise:
DO it with java scripting + iMacro. EVAL won't work all the time..
DO it with java scripting + iMacro. EVAL won't work all the time..
Hire the BoT-fReeak!
botspecialist.blogspot.com
botspecialist.blogspot.com
Re: Decision Making using iMacros/Possible Workarounds
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...!)
- 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...
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
Re: Decision Making using iMacros/Possible Workarounds
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...Grace wrote:I agree with petr, i know this is a dead thread (OLD thread) but the tips mentioned here are gold, Thanks OPpetr wrote:This is extremely useful! If you've got other tips on this subject, I'm all eyes )
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...
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
Re: Workarounds for Conditional Logic in Macro Code
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: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
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...!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...
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...
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...