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.

Moderators: Community Moderators, iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

Workarounds for Conditional Logic in Macro Code

by cietru141 on Thu Dec 26, 2013 11:56 am

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!
cietru141
 
Posts: 3
Joined: Tue Dec 17, 2013 10:41 am

Re: Decision Making using iMacros/Possible Workarounds

by chivracq on Mon Jan 20, 2014 9:20 am

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)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 5730
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Decision Making using iMacros/Possible Workarounds

by chivracq on Sun Feb 16, 2014 7:22 pm

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)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 5730
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Decision Making using iMacros/Possible Workarounds

by petr on Tue Feb 18, 2014 4:42 am

This is extremely useful! If you've got other tips on this subject, I'm all eyes :))
petr
 
Posts: 53
Joined: Thu Jun 27, 2013 2:19 pm

Re: Decision Making using iMacros/Possible Workarounds

by chivracq on Tue Feb 18, 2014 5:02 am

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 3:39 pm, edited 1 time in total.
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 5730
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Decision Making using iMacros/Possible Workarounds

by sightunseen on Thu Feb 20, 2014 10:52 pm

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.
sightunseen
 
Posts: 67
Joined: Thu Apr 18, 2013 9:54 pm

Re: Decision Making using iMacros/Possible Workarounds

by chivracq on Fri Feb 21, 2014 6:08 am

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)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 5730
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Decision Making using iMacros/Possible Workarounds

by janib4all on Mon Mar 17, 2014 2:42 am

My advise:

DO it with java scripting + iMacro. EVAL won't work all the time..
Hire the BoT-fReeak!
botspecialist.blogspot.com
janib4all
 
Posts: 132
Joined: Tue Jul 20, 2010 11:44 pm
Location: Karachi, Sindh, Pakistan

Re: Decision Making using iMacros/Possible Workarounds

by chivracq on Fri Jul 25, 2014 9:13 am

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".


+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 Sun Feb 26, 2017 11:49 am, edited 1 time in total.
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 5730
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Decision Making using iMacros/Possible Workarounds

by Grace on Thu Sep 15, 2016 8:54 am

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
Last edited by Grace on Sat Oct 15, 2016 12:43 am, edited 1 time in total.
Grace
 
Posts: 2
Joined: Thu Sep 15, 2016 8:51 am
Location: USA

Re: Decision Making using iMacros/Possible Workarounds

by chivracq on Thu Sep 15, 2016 9:26 am

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...)
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 5730
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Workarounds for Conditional Logic in Macro Code

by Sharoun on Sun Feb 26, 2017 6:54 am

, 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
Last edited by Sharoun on Wed Mar 01, 2017 1:55 pm, edited 1 time in total.
Sharoun
 
Posts: 1
Joined: Sun Feb 26, 2017 6:50 am

Re: Workarounds for Conditional Logic in Macro Code

by chivracq on Sun Feb 26, 2017 11:55 am

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...
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 5730
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)


Return to General Support & Discussions

Who is online

Users browsing this forum: No registered users and 4 guests

Website Monitoring