Something like "if" and "else" to use in iMacros?

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
KauanGP
Posts: 4
Joined: Tue Jun 29, 2021 11:12 pm

Something like "if" and "else" to use in iMacros?

Post by KauanGP » Wed Jun 30, 2021 1:13 am

iMacros 10.1.1 "Free"
Windows 7
Chrome 91.0.4472.114

Hello, this is my first time creating a topic in this forum, i hope the information i provided is enough, well, my problem is quite simple: on one page there is an "A" button (I'll call it that for better understanding), and when I click on it another button appears that may contain the text "1" or "2", if the number "1" appears, click the "A" button again until the number "2" appears, when the number "2" appears , after clicking on it will open another page with a button numbered "3", after clicking on the button numbered "3" it will reload the page to check if the button "3" was actually clicked (sometimes the page with the button " 3" does not count the click), if it was not clicked, it will reload again and click the "3" button until the page counts the click, and this is my problem, if it were in javascript it would be easy to solve with "if" and "else ", but on iMacros I have no idea how to do this and if it's possible to do it. (Sorry for errors, my english is very bad so i used Google Translate)

Code: Select all

Wait seconds=2
TAB T=1

//when click on this button another button appears on the page which can be number "1" or number "2"
TAG POS=1 TYPE=BUTTON ATTR=TXT:A
Wait seconds=1

//if the number "1" appears I want to click again on the "A" button until the number "2" appears
TAG POS=1 TYPE=BUTTON ATTR=TXT:1

//if number "2" appears, when click on this button another page will open with a button number "3"
TAG POS=1 TYPE=BUTTON ATTR=TXT:2

Wait seconds=3
TAB T=2

//when click on button "3" i will reload the page to see if it was clicked
TAG POS=1 TYPE=BUTTON ATTR=TXT:3
Wait seconds=1

//if after reloading the page button "3" was not clicked, it will be in a loop between reloading and clicking until confirming that it was clicked
REFRESH
Wait seconds=5

TAB T=1
TAB CLOSEALLOTHERS
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Something like "if" and "else" to use in iMacros?

Post by chivracq » Wed Jun 30, 2021 1:41 am

KauanGP wrote:
Wed Jun 30, 2021 1:13 am

Code: Select all

iMacros 10.1.1 "Free"
 Windows 7
 Chrome 91.0.4472.114
Hello, this is my first time creating a topic in this forum, i hope the information i provided is enough, well, my problem is quite simple: on one page there is an "A" button (I'll call it that for better understanding), and when I click on it another button appears that may contain the text "1" or "2", if the number "1" appears, click the "A" button again until the number "2" appears, when the number "2" appears , after clicking on it will open another page with a button numbered "3", after clicking on the button numbered "3" it will reload the page to check if the button "3" was actually clicked (sometimes the page with the button " 3" does not count the click), if it was not clicked, it will reload again and click the "3" button until the page counts the click, and this is my problem, if it were in javascript it would be easy to solve with "if" and "else ", but on iMacros I have no idea how to do this and if it's possible to do it. (Sorry for errors, my english is very bad so i used Google Translate)

Code: Select all

Wait seconds=2
TAB T=1

//when click on this button another button appears on the page which can be number "1" or number "2"
TAG POS=1 TYPE=BUTTON ATTR=TXT:A
Wait seconds=1

//if the number "1" appears I want to click again on the "A" button until the number "2" appears
TAG POS=1 TYPE=BUTTON ATTR=TXT:1

//if number "2" appears, when click on this button another page will open with a button number "3"
TAG POS=1 TYPE=BUTTON ATTR=TXT:2

Wait seconds=3
TAB T=2

//when click on button "3" i will reload the page to see if it was clicked
TAG POS=1 TYPE=BUTTON ATTR=TXT:3
Wait seconds=1

//if after reloading the page button "3" was not clicked, it will be in a loop between reloading and clicking until confirming that it was clicked
REFRESH
Wait seconds=5

TAB T=1
TAB CLOSEALLOTHERS

Mini-Compliment on the Good Quality for your Post... :D

OK, yep-yep, it's possible to achieve some Conditional Logic in pure '.iim', have a Look at the following Thread where I explained several of the Techniques I use...: :idea:
- Re: Workarounds for Conditional Logic in Macro Code

You'll find several other Threads linked to at the end of that Thread where I "from time to time" maintain a List of "interesting" Threads and you can probably find some more if you search the Forum using "conditional+[whatever Functionality]", => "conditional+refresh" for example... :idea:

And for the 2nd Click on the "A" Button if the "1" appears, you can probably use 'Relative Positioning'... :idea:
- (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: Something like "if" and "else" to use in iMacros?

Post by chivracq » Wed Jun 30, 2021 2:29 pm

A lot of Reading I guess, from all the Links to "interesting" Threads I provided, ah-ah...!, but "dare" to post some Update(s) to show your "Progress", or to "shout" if you get stuck or don't understand some Technique/Mechanism... :wink:

I'm here to help, and any other Advanced User(s) that might jump into the Thread, but I/we won't be writing your Script... I help Users by making them understand how iMacros works, and what Functionality can be achieved with it, but I "guide" Users and let them find "the"/a Solution and get their Script to work by themselves..., which is also much more rewarding for them/yourself anyway... :idea:
(And you didn't post the URL of your Site, so I can only give "Generic" Advice anyway...)
- (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...
KauanGP
Posts: 4
Joined: Tue Jun 29, 2021 11:12 pm

Re: Something like "if" and "else" to use in iMacros?

Post by KauanGP » Wed Jun 30, 2021 3:17 pm

chivracq wrote:
Wed Jun 30, 2021 2:29 pm
A lot of Reading I guess, from all the Links to "interesting" Threads I provided, ah-ah...!, but "dare" to post some Update(s) to show your "Progress", or to "shout" if you get stuck or don't understand some Technique/Mechanism... :wink:

I'm here to help, and any other Advanced User(s) that might jump into the Thread, but I/we won't be writing your Script... I help Users by making them understand how iMacros works, and what Functionality can be achieved with it, but I "guide" Users and let them find "the"/a Solution and get their Script to work by themselves..., which is also much more rewarding for them/yourself anyway... :idea:
(And you didn't post the URL of your Site, so I can only give "Generic" Advice anyway...)
Oh yes, sorry for the delay, I'm researching more about iMacros commands, because until yesterday I didn't even know what "EXTRACT" or "EVAL" was, because my main language is Brazilian Portuguese and I always have to keep translating for me to try to understand, but sometimes the translator does not translate effectively. Today I was able to understand how "EXTRACT" works and I found its functions very useful, I will certainly use it in future macros. Now back to my problem, I'm researching about "EVAL" but I couldn't understand it very well, from what I understand inside it I can use the js conditional logic (sorry if I'm wrong), but they are inside "EVAL", how can I use them in commands like "TAG" for example?
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Something like "if" and "else" to use in iMacros?

Post by chivracq » Wed Jun 30, 2021 3:42 pm

"... from what I understand inside it I can use the js conditional logic (sorry if I'm wrong),"
=> Yep, that's correct, but only for "Data Manipulation", so the Input will be String(s)/Number(s)/Array(s), and the Output will be a String or a Number.

"... but they are inside "EVAL", how can I use them in commands like "TAG" for example?"
=> I usually let 'EVAL()' spit out a "1"/"0" Number to reuse for the 'TAG' Command on the 'POS' Parameter with the Var computed from 'EVAL()' like in "TAG POS={{!VAR1}}".
=> "TAG POS=1" will click your Button, and "TAG POS=0" won't do anything...! ('!ERRORIGNORE' needs to be activated in this Case..., and you'll usually want to shorten '!TIMEOUT_STEP' to avoid your Script waiting for the Default 6 Sec for each 'TAG' Statement...)
- (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...
KauanGP
Posts: 4
Joined: Tue Jun 29, 2021 11:12 pm

Re: Something like "if" and "else" to use in iMacros?

Post by KauanGP » Wed Jun 30, 2021 4:05 pm

Oh, I finally understand how "EVAL" works, you explain it very well :D, but I have one more question: I used this command to extract the text from the button (which would be "1" or "2")

Code: Select all

TAG POS =1 TYPE=p ATTR=TXT:* EXTRACT=TXT
would I be able to put this extracted text inside the eval? example:

Code: Select all

SET !VAR1 EVAL("var x={{!EXTRACT}}; if(x==1){x.replace(1)} else{x.replace(0)};x;")
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Something like "if" and "else" to use in iMacros?

Post by chivracq » Wed Jun 30, 2021 4:16 pm

KauanGP wrote:
Wed Jun 30, 2021 4:05 pm
Oh, I finally understand how "EVAL" works, you explain it very well :D, but I have one more question: I used this command to extract the text from the button (which would be "1" or "2")

Code: Select all

TAG POS =1 TYPE=p ATTR=TXT:* EXTRACT=TXT
would I be able to put this extracted text inside the eval? example:

Code: Select all

SET !VAR1 EVAL("var x={{!EXTRACT}}; if(x==1){x.replace(1)} else{x.replace(0)};x;")

Euh, yep, this is "more or less" correct, and "your" Syntax would maybe work, but here is the Syntax I use:

Code: Select all

SET !EXTRACT NULL
TAG POS=1 TYPE=P ATTR=TXT:* EXTRACT=TXT
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var z; if(s==1){z=1;} else{z=0;}; z;")
PROMPT EXTRACT:<SP>_{{!EXTRACT}}_<BR>VAR1:<SP>_{{!VAR1}}_
... But you'll find 100's of Sample Codes on the Forum, and if posted by me, using the Syntax that I know works perfectly, and is easy to reuse, extend, and debug...! :idea:
- (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...
KauanGP
Posts: 4
Joined: Tue Jun 29, 2021 11:12 pm

Re: Something like "if" and "else" to use in iMacros?

Post by KauanGP » Wed Jun 30, 2021 4:29 pm

Very good! It's working perfectly, I was just getting an error because what was being extracted was a text and not the numbers "1" and "2" so I put

Code: Select all

SET !VAR1 EVAL("var s='{{!EXTRACT}}' ; var z; if(s=='text'){z=1;} else{z=0;}; z;")
then I noticed that the ( ' ' ) were missing in the 'text', I put it and it worked perfectly. I don't even know how to thank you, thank you so much for your help :)

Edit: Oh yes, I forgot to say, the topic you referred me to was very useful for me, I learned several commands in it, thanks again!
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Something like "if" and "else" to use in iMacros?

Post by chivracq » Wed Jun 30, 2021 4:40 pm

KauanGP wrote:
Wed Jun 30, 2021 4:29 pm
Very good! It's working perfectly, I was just getting an error because what was being extracted was a text and not the numbers "1" and "2" so I put

Code: Select all

SET !VAR1 EVAL("var s='{{!EXTRACT}}' ; var z; if(s=='text'){z=1;} else{z=0;}; z;")
then I noticed that the ( ' ' ) were missing in the 'text', I put it and it worked perfectly. I don't even know how to thank you, thank you so much for your help :)

Edit: Oh yes, I forgot to say, the topic you referred me to was very useful for me, I learned several commands in it, thanks again!

OK, glad it's working now, and that you understood the "Principle"...! :D
- (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