Help with if/else statements!

Discussions and Tech Support related to the iMacros Google Chrome extension.
Forum rules
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
20kevin20
Posts: 4
Joined: Sat Nov 19, 2016 1:50 pm

Help with if/else statements!

Post by 20kevin20 » Sat Nov 19, 2016 2:09 pm

Hello!

I'm new on iMacros and I have been trying for over 5 hours already to figure how if/else statements work. I do not have any experience with coding and stuff like this, so I thought maybe it's easy for someone to help me out with the code.
In my mind it's pretty simple.. now I don't know how simple it is to code it too. I got a website on which I want to code iMacros to automatically buy items everytime my balance is >$0.00. Here is what I want exactly to happen:

Go to link X (with 120 sec timeout)
Check if the text "Balance: $0.00" exists.
IF IT DOES:
----Go to line 1 (reload macro)
ELSE:
----Check if the word "parameters" exists.
----IF IT DOES:
--------Reload macro (go to 1st line)
----ELSE:
--------Click the button "Add Item", go to link Y, click the button "Confirm", and then "Yes"

Thank you VERY MUCH for the help, guys. I wish I will find someone here to help me out. Thank you, again! Also, regarding the "reload macro" function, I researched and found nothing about it... So if it doesn't exist, you can use the !ERRORIGNORE Yes statement and add a random error code to force the macro to stop, and I'll use the "Play Macro Repeatedly" function to loop it.

THANK YOU!
20kevin20
Posts: 4
Joined: Sat Nov 19, 2016 1:50 pm

Re: Help with if/else statements!

Post by 20kevin20 » Tue Nov 22, 2016 8:16 pm

Okay so forget about the first post - I thought of a simplified version, and here it is:

Code: Select all

SET !ERRORIGNORE YES
SET !TIMEOUT_PAGE 120
And then... I need this following one:

1. Go to the specified URL
2. If the word "parameters" exists (part of a H4 text): TAG POS=1 TYPE=BUTTON ATTR=TXT:Add<SP>in<SP>Cart; else: give error so that the macro could repeat.

Thank you, again for helping!
chivracq
Posts: 8871
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Help with if/else statements!

Post by chivracq » Tue Nov 22, 2016 8:45 pm

20kevin20 wrote:Hello!

I'm new on iMacros and I have been trying for over 5 hours already to figure how if/else statements work. I do not have any experience with coding and stuff like this, so I thought maybe it's easy for someone to help me out with the code.
In my mind it's pretty simple.. now I don't know how simple it is to code it too. I got a website on which I want to code iMacros to automatically buy items everytime my balance is >$0.00. Here is what I want exactly to happen:

Go to link X (with 120 sec timeout)
Check if the text "Balance: $0.00" exists.
IF IT DOES:
----Go to line 1 (reload macro)
ELSE:
----Check if the word "parameters" exists.
----IF IT DOES:
--------Reload macro (go to 1st line)
----ELSE:
--------Click the button "Add Item", go to link Y, click the button "Confirm", and then "Yes"

Thank you VERY MUCH for the help, guys. I wish I will find someone here to help me out. Thank you, again! Also, regarding the "reload macro" function, I researched and found nothing about it... So if it doesn't exist, you can use the !ERRORIGNORE Yes statement and add a random error code to force the macro to stop, and I'll use the "Play Macro Repeatedly" function to loop it.

THANK YOU!
20kevin20 wrote:Okay so forget about the first post - I thought of a simplified version, and here it is:

Code: Select all

SET !ERRORIGNORE YES
SET !TIMEOUT_PAGE 120
And then... I need this following one:

1. Go to the specified URL
2. If the word "parameters" exists (part of a H4 text): TAG POS=1 TYPE=BUTTON ATTR=TXT:Add<SP>in<SP>Cart; else: give error so that the macro could repeat.

Thank you, again for helping!
Yeah, but sorry..., => "CIM" for me to read...! :mrgreen: (Read my Sig...)
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
20kevin20
Posts: 4
Joined: Sat Nov 19, 2016 1:50 pm

Re: Help with if/else statements!

Post by 20kevin20 » Tue Nov 22, 2016 8:50 pm

chivracq wrote:Yeah, but sorry..., => "CIM" for me to read...! :mrgreen: (Read my Sig...)
Sure! Sorry for missing out on that. I'm using iMacros v8.4.4 on Chrome v54.0.2840.99 m (64-bit). The OS I'm using is Windows 7 x64, up to date with the latest updates and drivers. You don't need to read the first post though - it's long and has a more complicated idea, so you can skip it!

EDIT: If it helps, here you got the source code for the word that needs to be found:

Code: Select all

<h4 class="text-center" style="margin-bottom: 25px;">parameters</h4>
chivracq
Posts: 8871
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Help with if/else statements!

Post by chivracq » Tue Nov 22, 2016 9:19 pm

20kevin20 wrote:
chivracq wrote:Yeah, but sorry..., => "CIM" for me to read...! :mrgreen: (Read my Sig...)
Sure! Sorry for missing out on that. I'm using

Code: Select all

iMacros v8.4.4 
on Chrome v54.0.2840.99 m (64-bit). 
The OS I'm using is Windows 7 x64, up to date with the latest updates and drivers.
You don't need to read the first post though - it's long and has a more complicated idea, so you can skip it!

EDIT: If it helps, here you got the source code for the word that needs to be found:

Code: Select all

<h4 class="text-center" style="margin-bottom: 25px;">parameters</h4>
Ah...!, that's much better...! :D
Always mention your FCI when you open a new Thread (or post for the first time in some existing Thread), many Commands are not implemented for all Browsers/Versions, and I usually simply don't even read the Qt and certainly don't answer if that Required Info is missing...

But OK, hum, yep, your Scenario looks "classical" and fairly simple, I would think...
You can simply "solve" it using Relative Positioning by first (trying to) tag(ging) your 'parameters' Element that you use as the "Anchor" in stg like:

Code: Select all

SET !ERRORIGNORE YES
URL GOTO=your_site...
TAG POS=1 TYPE=H4 ATTR=TXT:parameters
TAG POS=R1 TYPE=BUTTON ATTR=TXT:Add<SP>in<SP>Cart
'!TIMEOUT_PAGE' won't really play a role I think, but you may want to "tune" '!TIMEOUT_STEP' a bit to make it shorter than the Default 6 Sec or 12 Sec (=120/10) unless you deliberately want to check the Page every 6 or 12 Sec...

Here is some "interesting" further Reading about "Conditional Logic" in pure '.iim' with several (other) Techniques that I have mentioned/explained a bit (and use myself):
- Workarounds for Conditional Logic in Macro Code
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
20kevin20
Posts: 4
Joined: Sat Nov 19, 2016 1:50 pm

Re: Help with if/else statements!

Post by 20kevin20 » Tue Nov 22, 2016 9:40 pm

Thank you very much for the help!!! I read your post and now I understand a part of it, but if I want to, let's say, double my "Add in Cart" line? I mean, if the word "parameter" exists, I want it to add two items in cart. Should I just copy that POS=R1 line multiple times or I should add R2 to the second one?

I'm talking about something like this:

Code: Select all

SET !ERRORIGNORE YES
URL GOTO=your_site...
TAG POS=1 TYPE=H4 ATTR=TXT:parameters
TAG POS=R1 TYPE=BUTTON ATTR=TXT:Add<SP>in<SP>Cart
TAG POS=R1 TYPE=BUTTON ATTR=TXT:Add<SP>in<SP>Cart
chivracq
Posts: 8871
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Help with if/else statements!

Post by chivracq » Tue Nov 22, 2016 9:51 pm

20kevin20 wrote:Thank you very much for the help!!! I read your post and now I understand a part of it, but if I want to, let's say, double my "Add in Cart" line? I mean, if the word "parameter" exists, I want it to add two items in cart. Should I just copy that POS=R1 line multiple times or I should add R2 to the second one?

I'm talking about something like this:

Code: Select all

SET !ERRORIGNORE YES
URL GOTO=your_site...
TAG POS=1 TYPE=H4 ATTR=TXT:parameters
TAG POS=R1 TYPE=BUTTON ATTR=TXT:Add<SP>in<SP>Cart
TAG POS=R1 TYPE=BUTTON ATTR=TXT:Add<SP>in<SP>Cart
Well, I cannot really tell without seeing how the Page "works" and its HTML Structure...
The 2nd 'POS=R1' Element is then Relative to the 1st 'POS=R1' which then becomes its Anchor.
You need to test by yourself if that works or if you need to specify another Anchor or maybe re-specify the same Anchor with then stg like 'POS=R2' for the 2nd Item, I don't know...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
Post Reply