Page 1 of 1

Workarounds for Conditional Logic in Macro Code

Posted: Thu Dec 26, 2013 11:56 am
by cietru141
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!

Re: Decision Making using iMacros/Possible Workarounds

Posted: Mon Jan 20, 2014 9:20 am
by chivracq
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...

Re: Decision Making using iMacros/Possible Workarounds

Posted: Sun Feb 16, 2014 7:22 pm
by chivracq
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...

Re: Decision Making using iMacros/Possible Workarounds

Posted: Tue Feb 18, 2014 4:42 am
by petr
This is extremely useful! If you've got other tips on this subject, I'm all eyes :))

Re: Decision Making using iMacros/Possible Workarounds

Posted: Tue Feb 18, 2014 5:02 am
by chivracq
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...

Re: Decision Making using iMacros/Possible Workarounds

Posted: Thu Feb 20, 2014 10:52 pm
by sightunseen
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.

Re: Decision Making using iMacros/Possible Workarounds

Posted: Fri Feb 21, 2014 6:08 am
by chivracq
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...

Re: Decision Making using iMacros/Possible Workarounds

Posted: Mon Mar 17, 2014 2:42 am
by janib4all
My advise:

DO it with java scripting + iMacro. EVAL won't work all the time..

Re: Decision Making using iMacros/Possible Workarounds

Posted: Fri Jul 25, 2014 9:13 am
by chivracq
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...!)

Re: Decision Making using iMacros/Possible Workarounds

Posted: Thu Sep 15, 2016 8:54 am
by Grace
petr wrote:This is extremely useful! If you've got other tips on this subject,Phenq review 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

SOrry my bad chivracq, good on ya mate

Re: Decision Making using iMacros/Possible Workarounds

Posted: Thu Sep 15, 2016 9:26 am
by chivracq
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 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...)

Re: Workarounds for Conditional Logic in Macro Code

Posted: Sun Feb 26, 2017 6:54 am
by Sharoun
, SOrry my bad chivracq, good on ya mate my best my sizegenetics review I agree with petr, i know this is a dead thread (OLD thread) but the tips mentioned here are gold

Re: Workarounds for Conditional Logic in Macro Code

Posted: Sun Feb 26, 2017 11:55 am
by chivracq
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...!

Re: Decision Making using iMacros/Possible Workarounds

Posted: Thu Aug 17, 2017 3:53 pm
by Anna001
chivracq wrote:
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 on bulking steroids mentioned here are gold, Thanks OP

Thread is not "dead", I still maintain 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...)



Your experience helped inform me. I had been trying to use If My_Object Is Not Nothing also, but your other form looks like it's on the right path :)