"IF" conditional, the mother of all problems ..... help?

Discussions and Tech Support specific to the iMacros Firefox add-on.
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
Selmar
Posts: 15
Joined: Sat Jul 20, 2013 2:46 pm

"IF" conditional, the mother of all problems ..... help?

Post by Selmar » Mon Jul 29, 2013 7:22 pm

And the daughter of almost all solutions........

I have read about the conditional, but I learned nothing. It may be very difficult to explain in a simple way.

EVAL Imacros has only conditional, but not good for what I need.

To keep it simple does not have added a conditional, but the conditional is necessary for almost everything, really does not simplify, not having it.

Only you can make a conditional adding a fragment in another language, usually javascript.

Do not know if you can add in the imacros code, or do I need to put it in a separate file and call it from imacros, really I have no knowledge to do so.

Someone could help me?

I took an example of those who come in imacros, with the solution of this example I could move my macro.

I need someone to be kind enough to make it functional, so that I may take it and see what works, made and explained for dummies, so that I can understand.

Code: Select all

URL GOTO=http://demo.imacros.net/Automate/ExtractDemo
TAG POS=39 TYPE=TD ATTR=TXT:* EXTRACT=TXT
SET !VAR1 {{!EXTRACT}}
SET !EXTRACT NULL
URL GOTO=http://demo.imacros.net/Automate/TestForm1   
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:demo ATTR=NAME:name CONTENT="***Extract and Fill Demo***"
TAG POS=1 TYPE=TEXTAREA FORM=ID:demo ATTR=NAME:Remarks CONTENT="Extraction results:\n\nOne dollar costs {{!VAR1}} EURO, {{!VAR2}} Pounds or {{!VAR3}} Yen."
'-----------------------------------------------------------------------------------------------
If Var1 equals to 1.022 press "button1" (TAG POS=1 TYPE=BUTTON ATTR=TXT:Click<SP>to<SP>order<SP>now) 
;else press "button2"(TAG POS=1 TYPE=BUTTON ATTR=TXT:Click<SP>to<SP>order<SP>now)
------------------------------------------------------------------------------------------------
Button 1 and 2 are the same pq the macro only had one, but never mind then I would put in my macro two different buttons.

Thank you.

Selmar
User avatar
garyst1981
Posts: 125
Joined: Tue Jan 15, 2013 1:01 am
Location: Philadelphia, PA
Contact:

Re: "IF" conditional, the mother of all problems ..... help?

Post by garyst1981 » Tue Jul 30, 2013 1:53 pm

No hay IF como tal en iMacros... hay un workaround pero no es muy amigable... digamos que entras a una pagina en la cual puede aparecer un boton u otro, osea bajo ciertas condiciones aparece 1 boton y bajo ciertas otras condiciones aparece otro boton. Lo que tu quieres hacer, es dar clic en uno o en otro, cuando aparescan. Nunca aparecen los 2 al mismo tiempo, siempre es uno o el otro.

Si tu escribes algo como

Code: Select all

URL GOTO=http://paginaconunouotroboton.com
TAG POS=1 TYPE=BUTTON ATTR=TXT:BUTTON1
TAG POS=1 TYPE=BUTTON ATTR=TXT:BUTTON2
SOME MORE CODE
Lo que pasaria ahi es que, si al entrar a la pagina, el boton1 esta presente, lo vas a poder clickear, pero va a querer clickear el segundo y no va a estar, ya sea si ese boton te deja ahi o te lleva a otra pagina, si el boton 2 no esta, el script va a parar y marcar error.

Si al entrar a la pagina lo que pasa es que el boton presente es el boton 2. Al querer buscar el boton 1 el script va a marcar error, porque no lo va a encontrar... Para eso tenemos el comando SET !ERRORIGNORE que puede ser utilizado con YES o NO. Lo que este comando hace, es que cuando , es utilizado con YES, deja pasar todos los errores que pasen de ahi en adelante.... y cuando es utilizado con NO comienza a tomar en cuenta los errores.

Por lo tanto, lo que podemos hacer en ese ejemplo es

Code: Select all

URL GOTO=http://paginaconunouotroboton.com
SET !ERRORIGNORE YES
TAG POS=1 TYPE=BUTTON ATTR=TXT:BUTTON1
TAG POS=1 TYPE=BUTTON ATTR=TXT:BUTTON2
SET !ERRORIGNORE NO
SOME MORE CODE
Evaluando vemos.. Que pasa si al entrar ahi busca y el boton presente es el boton 2.? Va a fallar en encontrar el boton 1 pero lo va a ignorar, asi que seguira con el clic el el boton 2, y luego continuará con el resto del codigo, ahora si, tomando en cuenta los errores.
Que pasa si al entrar ahi, el boton presente es el boton 1.? Va a hacer click en el boton 1 y como el boton 2 no esta, va a fallar pero va a seguir con el script, siguiendo con el resto tomando ya en cuenta los errores.

Eso nos crea un statement de la forma

IF Boton 1 Existe, click it
then continua con el script
else click Boton 2

Espero que eso te de una idea de como crear un IF simple en iMacros
www.gustavorivera.com.mx
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: "IF" conditional, the mother of all problems ..... help?

Post by chivracq » Wed Jul 31, 2013 11:29 am

It's a bit useless for other Users to write in Spanish...

But I agree with Selmar, it would be VERY useful if iMacros could support a simple IF-THEN-ELSE routine in iim-Macros... With EVAL, you can only make the Macro abort its execution if the Condition is not met, you cannot make it to jump to another Line of Code...
- (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...
Selmar
Posts: 15
Joined: Sat Jul 20, 2013 2:46 pm

Re: "IF" conditional, the mother of all problems ..... help?

Post by Selmar » Wed Jul 31, 2013 5:36 pm

Chivac ok I try, but my English is very bad, if something is complicated it would also in Spanish.

As I promised in another post, Garyst1981, I put my real problem in image.

On the form you get to a point with two possibilities, that this "Aprobado" or that this "denegado".

the condional:

If extract is equal to "approved" select 1; Else select 2

This would work for both possibilities.

1-"Aprobado"

Image

2-"Denegado"

Image


This is my real problem, eval can not solve this, and the two possibilities exist simultaneously.

Any chance to put it, so that I can put it on my computer and it works, because I looked more I have not found anything useful for me.

It would be a tremendous help to me and to a lot of people who have to be like me.

A greeting Selmar

........ in Gary believe :)
User avatar
garyst1981
Posts: 125
Joined: Tue Jan 15, 2013 1:01 am
Location: Philadelphia, PA
Contact:

Re: "IF" conditional, the mother of all problems ..... help?

Post by garyst1981 » Wed Jul 31, 2013 8:11 pm

chivracq wrote:It's a bit useless for other Users to write in Spanish...

But I agree with Selmar, it would be VERY useful if iMacros could support a simple IF-THEN-ELSE routine in iim-Macros... With EVAL, you can only make the Macro abort its execution if the Condition is not met, you cannot make it to jump to another Line of Code...
Sorry chivrac, true, translating

There's no IF in per-se in iMacros... there's a workaround but it is not very friendly... let's say that you go to a page which can show 1 of 2 buttons, in other words, under certain conditions it will show 1 button, and under other certain conditions it will show the other button, what we want to do is click on one or another when appear. We are never getting both at the same time.

if you type something like

Code: Select all

URL GOTO=http://paginaconunouotroboton.com
TAG POS=1 TYPE=BUTTON ATTR=TXT:BUTTON1
TAG POS=1 TYPE=BUTTON ATTR=TXT:BUTTON2
SOME MORE CODE
What is going to happen is one of the following 2 options.

A. Button 1 appears. If button 1 appears, the script will click it, but then it will search for button 2. So the script will fail and stop,
B. Button 2 appears. If button 2 appears, it will try to click on button 1 but since it is not there, is going to fail without even try to search for button 2

For that case we can use the command !ERRORIGNORE that can take YES and NO. What this command does is to ignore errors on the following lines under it when its used with YES. And stop ignoring errors on the following lines when is used with NO.

Therefore, what we can do is the following:

Code: Select all

URL GOTO=http://paginaconunouotroboton.com
SET !ERRORIGNORE YES
TAG POS=1 TYPE=BUTTON ATTR=TXT:BUTTON1
TAG POS=1 TYPE=BUTTON ATTR=TXT:BUTTON2
SET !ERRORIGNORE NO
SOME MORE CODE
Evaluating we can see the following:

For the case where we get the button 1 when landing on that page, is going to click it... Then is going to fail on finding (and clicking) button 2 but is going to ignore it and keep going. For the case where we get the button 2 is going to fail on finding (and clicking) button 1 but is going to ignore it and keep going, finding later the button 2 and clicking it.

That creates a statement like

IF Button 1 exists click it
then keep going
else click button 2

That can give us an idea of how to use !ERRORIGNORE YES and NO to make a really basic IF
www.gustavorivera.com.mx
User avatar
garyst1981
Posts: 125
Joined: Tue Jan 15, 2013 1:01 am
Location: Philadelphia, PA
Contact:

Re: "IF" conditional, the mother of all problems ..... help?

Post by garyst1981 » Wed Jul 31, 2013 10:20 pm

Ok lets go back to the other post...

remember that I created a form on Google Docs and then I extracted it with?

Code: Select all

'Hitting submit button
TAG POS=1 TYPE=INPUT:SUBMIT FORM=ACTION:https://docs.google.com/forms/d/1TeWc2RoeHyCX2DOAXBTzl_uYIS2QrBnfGosuN41d1Mw/formResponse ATTR=NAME:submit
'Then extracting the result text
TAG POS=1 TYPE=DIV ATTR=CLASS:ss-confirmation EXTRACT=TXT
'Then saving it on the form
SAVEAS TYPE=EXTRACT FOLDER=* FILE=address2.csv
Ok what you want to do is when you extract that, no matter the result, use it in a way that it always clicks on the Approved one? or do u want it to click on the result you obtained?

___________________________________________________________________________________________________________________________________

Recuerdas cuando hice una forma en Google Docs que extraia el resultado de la siguiente manera?

Code: Select all

'Hitting submit button
TAG POS=1 TYPE=INPUT:SUBMIT FORM=ACTION:https://docs.google.com/forms/d/1TeWc2RoeHyCX2DOAXBTzl_uYIS2QrBnfGosuN41d1Mw/formResponse ATTR=NAME:submit
'Then extracting the result text
TAG POS=1 TYPE=DIV ATTR=CLASS:ss-confirmation EXTRACT=TXT
'Then saving it on the form
SAVEAS TYPE=EXTRACT FOLDER=* FILE=address2.csv
Lo que quieres es que cuando extraiga el resultado, no importa cual sea, siempre clickee en Aprobado, sin importar la posicion? o quieres que haga click en el resultado que extrajiste, sin importar si esta arriba o abajo?

En otras palabras, quieres:

Si extraje Aprobado, click en Aprobado
Si extraje Reprobado, click en Reprobado

O

Si extraje Aprobado, click en Aprobado
Si extraje Reprobado, clicn en Aprobado
www.gustavorivera.com.mx
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: "IF" conditional, the mother of all problems ..... help?

Post by chivracq » Mon Aug 05, 2013 4:30 pm

Selmar, I've been thinking about your problem and I think that an easy solution can be achieved using Relative Positioning in your case...
http://wiki.imacros.net/Data_Extraction

I use a similar example:
TAG POS=1 TYPE=FONT ATTR=TXT:Aprobado
TAG POS=R-1 TYPE=INPUT:CHECKBOX FORM=NAME:* ATTR=NAME:* CONTENT=YES

Just record the correct syntax in iMacros for finding/clicking on the word "Aprobado" and selecting the corresponding Checkbox, and you just use TAG POS=R-1 for applying the real click that you want to the first Checkbox that iMacros will find on the LEFT of "Aprobado"...
- (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: "IF" conditional, the mother of all problems ..... help?

Post by chivracq » Sat Aug 10, 2013 5:43 am

Since my last Reply, I've started using this method/workaround quite extensively to palliate the lack of IF_Conditional_Programming in IIM Macros and it's quite powerful and I like it...
(Thanks Selmar and GarySt1981 for giving me the idea to think in this direction...)
- (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...
Selmar
Posts: 15
Joined: Sat Jul 20, 2013 2:46 pm

Re: "IF" conditional, the mother of all problems ..... help?

Post by Selmar » Sun Aug 11, 2013 8:44 pm

Sorry for the delay I've been a few days of vacation.

Thanks Garys for your answer, the solution is your second option:

Si extraje Aprobado, click en Aprobado
Si extraje Reprobado, clicn en Aprobado


Thank you very much to you Chivracq,it seems you've found a gold mine for me.

I did not think that would solve the problem, my low level, but I'm encouraging me at times.

Although I have several questions, in the table, are several times the word "Aprobado", does that always elect the first to appear? Would not be changed by the second to appear for example?

I can do that instead of a txt Specifically, look for a value in the database, that change in each loop?

something like this:

Code: Select all

TAG POS = 1 TYPE = FONT ATTR = TXT: {{! COL1}}
TAG POS = R-1 TYPE = INPUT: CHECKBOX FORM = NAME: * ATTR = NAME: * CONTENT = YES
Is it possible?

Thank you very much to both.

Selmar.
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: "IF" conditional, the mother of all problems ..... help?

Post by chivracq » Wed Aug 14, 2013 10:40 pm

If it's always the word "Aprobado" that you are looking for, it's not very useful to use a CSV and repeat the word "Aprobado" 20 times, it's the TAG POS=x that you want to increment, because TAG POS=1 will always find only the first one.

If your Page always contains let's say 13 blocks with 13 times the word "Aprobado", then you just repeat your Code 13 times with:

Code: Select all

TAG POS=1 TYPE=FONT ATTR=TXT:Aprobado
TAG POS=R-1 TYPE=INPUT:CHECKBOX FORM=NAME:* ATTR=NAME:* CONTENT=YES

TAG POS=2 TYPE=FONT ATTR=TXT:Aprobado
TAG POS=R-1 TYPE=INPUT:CHECKBOX FORM=NAME:* ATTR=NAME:* CONTENT=YES

TAG POS=3 TYPE=FONT ATTR=TXT:Aprobado
TAG POS=R-1 TYPE=INPUT:CHECKBOX FORM=NAME:* ATTR=NAME:* CONTENT=YES

...etc
If you know that you always get between 10 and max 20 occurrences, you repeat your Code 20 times and you put

Code: Select all

SET !ERRORIGNORE YES
SET !TIMEOUT 1
before the 1st Block and you put back

Code: Select all

SET !TIMEOUT 60
after the 20th Block.

When your Script is running, even if there are only 10 "Aprobado" on the Page, the extra 10 Blocks will only take 2 seconds to run for nothing.

Or you can play with "SET !TIMEOUT_STEP 1", which will take 1 sec per Step... i.e. 20 secs for 10 Blocks of 2 Lines for nothing...

(But a Checkbox or a RadioButton works perfectly with "SET !TIMEOUT 1", even if you have 100's of them on the same Page...)
- (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...
Selmar
Posts: 15
Joined: Sat Jul 20, 2013 2:46 pm

Re: "IF" conditional, the mother of all problems ..... help?

Post by Selmar » Mon Aug 19, 2013 10:15 pm

Thanks chivracq for the reply, it will be useful.

But ...... houston we have a problem ....

If I put your system:

Code: Select all

TAG POS=1 TYPE=FONT ATTR=TXT:Aprobado
TAG POS=R-1 TYPE=INPUT:CHECKBOX FORM=NAME:* ATTR=NAME:* CONTENT=YES
Find "Aprobado" correctly ......
Image


But in the second step, mark the second line of the table, because the checkbox is closer ........
Image


Any idea to solve this, like saying "the closer to the left."

Thanks
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: "IF" conditional, the mother of all problems ..... help?

Post by chivracq » Wed Aug 21, 2013 1:40 am

For finding "Aprobado" on each line, it will be "TAG POS=1 / =2 / =3 ...etc", but the closest on the left for the Checkbox on each line will always be "TAP POS=R-1"...

But the example I gave you that I am using myself was with a Checkbox, from your PrintScreen, it looks more like a RadioButton.

Experiment with the Record-Mode to find the correct Syntax for the Elements that you want to be able to select...
- (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...
Selmar
Posts: 15
Joined: Sat Jul 20, 2013 2:46 pm

Re: "IF" conditional, the mother of all problems ..... help?

Post by Selmar » Fri Aug 23, 2013 9:11 pm

You're right about everything Chivracq..

My mistake was to put "R1" instead of "R-1"

Now it works fine.

Thank you so much for everything.
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: "IF" conditional, the mother of all problems ..... help?

Post by chivracq » Sat Aug 24, 2013 11:48 pm

Selmar wrote:You're right about everything Chivracq..

My mistake was to put "R1" instead of "R-1"

Now it works fine.

Thank you so much for everything.
OK, nice to hear... Happy I could help...
- (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: "IF" conditional, the mother of all problems ..... help?

Post by chivracq » Sun Apr 09, 2017 3:27 am

For the Records, some new User (@BoredFish) tried to post on this Thread, I disapproved the Post, was not in ENGLISH...
- (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