Help with if/else statements!

Discussions and Tech Support related to the iMacros Google Chrome extension.

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.

Help with if/else statements!

by 20kevin20 on Sat Nov 19, 2016 7:09 am

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 6:50 am

Re: Help with if/else statements!

by 20kevin20 on Tue Nov 22, 2016 1: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!
20kevin20
 
Posts: 4
Joined: Sat Nov 19, 2016 6:50 am

Re: Help with if/else statements!

by chivracq on Tue Nov 22, 2016 1: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)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 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: 5962
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Help with if/else statements!

by 20kevin20 on Tue Nov 22, 2016 1: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>
20kevin20
 
Posts: 4
Joined: Sat Nov 19, 2016 6:50 am

Re: Help with if/else statements!

by chivracq on Tue Nov 22, 2016 2: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)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 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: 5962
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Help with if/else statements!

by 20kevin20 on Tue Nov 22, 2016 2: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
20kevin20
 
Posts: 4
Joined: Sat Nov 19, 2016 6:50 am

Re: Help with if/else statements!

by chivracq on Tue Nov 22, 2016 2: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)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 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: 5962
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)


Return to iMacros for Chrome

Who is online

Users browsing this forum: No registered users and 1 guest

-->