Need help figuring out an If statement

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.

Need help figuring out an If statement

by darklordofsith on Wed Jan 31, 2018 9:46 am

Hi All,

The iMacros forums have been an incredible help for me and I've used them to the best of my abilities but I am stuck at this point. I am using IMacros 10.0.2.2823 browser along with IE10 IMacros on Windows 10.

So I have the following code running:

SET !REPLAYSPEED FAST
TAG POS=1 TYPE=BUTTON ATTR=TXT:Refresh
SET !TIMEOUT_STEP 0
SET !ERRORIGNORE YES
TAG POS=1 TYPE=A ATTR=HREF:/requests/details/****
WAIT SECONDS = 1.0
TAG POS=1 TYPE=SPAN FORM=NAME:NoFormName ATTR=TXT:Approve
TAG POS=1 TYPE=INPUT:RADIO FORM=NAME:NoFormName ATTR=NAME:status CONTENT=YES
TAG POS=1 TYPE=BUTTON ATTR=TXT:Call


This is constantly clicking the refresh button within a page and looking for a dynamic link that pops up every few minutes/hours. After the link pops up, I would like to go to that link and push the buttons as indicated above.

I was wondering if there is a way to make an If statement so that it only runs that part of the code if the link pops up and the script goes to it. Otherwise I would like the page to keep refreshing every 0.5-0.7 seconds. I am a complete novice at programming and cannot figure out how to make an If Statement. I would be happy to provide pizza/beer money to anyone that can help me solve this because I have grown so frustrated by all my failed attempts at doing it. I tried to open the link in a new tab and do it, but that just slowed everything down. I'm not sure where to go now.
darklordofsith
 
Posts: 4
Joined: Wed Jan 31, 2018 9:34 am

Re: Need help figuring out an If statement

by chivracq on Wed Jan 31, 2018 11:01 am

darklordofsith wrote:Hi All,

The iMacros forums have been an incredible help for me and I've used them to the best of my abilities but I am stuck at this point. I am using
Code: Select all
IMacros 10.0.2.2823 browser along with IE10 IMacros on Windows 10.


So I have the following code running:

Code: Select all
SET !REPLAYSPEED  FAST
TAG POS=1 TYPE=BUTTON ATTR=TXT:Refresh
SET !TIMEOUT_STEP 0
SET !ERRORIGNORE YES
TAG POS=1 TYPE=A ATTR=HREF:/requests/details/****
WAIT SECONDS = 1.0
TAG POS=1 TYPE=SPAN FORM=NAME:NoFormName ATTR=TXT:Approve
TAG POS=1 TYPE=INPUT:RADIO FORM=NAME:NoFormName ATTR=NAME:status CONTENT=YES
TAG POS=1 TYPE=BUTTON ATTR=TXT:Call


This is constantly clicking the refresh button within a page and looking for a dynamic link that pops up every few minutes/hours. After the link pops up, I would like to go to that link and push the buttons as indicated above.

I was wondering if there is a way to make an If statement so that it only runs that part of the code if the link pops up and the script goes to it. Otherwise I would like the page to keep refreshing every 0.5-0.7 seconds. I am a complete novice at programming and cannot figure out how to make an If Statement. I would be happy to provide pizza/beer money to anyone that can help me solve this because I have grown so frustrated by all my failed attempts at doing it. I tried to open the link in a new tab and do it, but that just slowed everything down. I'm not sure where to go now.

Hum..., very clever to mention "Beer" as an Incentive, that always works..., ah-ah...! 8)

I've already provided some easy Sol for your Scenario... You simply need to (try to) extract your Link before actually clicking on it to check if it's there or not and using 'EVAL()' to spit out a "1"/"0" to reuse for all 'TAG POS=n' after the 'Refresh' ('TAG POS=0' won't do anything) and the same "1"/"0" can even be use for the 'WAIT' to make it conditional, stg like:
Code: Select all
TAG POS=1 TYPE=BUTTON ATTR=TXT:Refresh
SET !TIMEOUT_STEP 0
SET !ERRORIGNORE YES
SET !EXTRACT_TEST_POPUP NO

'Check if Link  is there:
SET !EXTRACT NULL
TAG POS=1 TYPE=A ATTR=HREF:/requests/details/**** EXTRACT=TXT
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var z; if(s!='#EANF#'){z=1;} else{z=0;}; z;")

TAG POS={{!VAR1}} TYPE=A ATTR=HREF:/requests/details/****
WAIT SECONDS={{!VAR1}}
TAG POS={{!VAR1}} TYPE=SPAN FORM=NAME:NoFormName ATTR=TXT:Approve
TAG POS={{!VAR1}} TYPE=INPUT:RADIO FORM=NAME:NoFormName ATTR=NAME:status CONTENT=YES
TAG POS={{!VAR1}} TYPE=BUTTON ATTR=TXT:Call

If you find the [0-1] Values not modular enough for the 'WAIT' Statement, use a second Var to spit out the Values that you want, that's it...
- (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: 6687
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Need help figuring out an If statement

by darklordofsith on Wed Jan 31, 2018 9:57 pm

Thank you so much! I think that might just be what I'm looking for. I have one more question. Is there a way to make the page wait ~1 second after it loads before it tries clicking the buttons? I tried putting a wait command in there, but it just automatically made the script wait 1 second every time it was running. I'd like it to wait that amount, only if the page is loaded.

P.S. I'm a man of my word....please DM me your Paypal or Venmo account and I'll send you over the pizza money :D
darklordofsith
 
Posts: 4
Joined: Wed Jan 31, 2018 9:34 am

Re: Need help figuring out an If statement

by chivracq on Wed Jan 31, 2018 10:26 pm

darklordofsith wrote:Thank you so much! I think that might just be what I'm looking for. I have one more question. Is there a way to make the page wait ~1 second after it loads before it tries clicking the buttons? I tried putting a wait command in there, but it just automatically made the script wait 1 second every time it was running. I'd like it to wait that amount, only if the page is loaded.

P.S. I'm a man of my word....please DM me your Paypal or Venmo account and I'll send you over the pizza money :D

Well, that's exactly the Sol I gave you I would think, your Script will wait '!VAR1' Seconds and '!VAR1' =1 (only) if your Link was found... 8)
Or am I missing stg...?

And don't worry about "pizza money", hum..., "beer money" sounds nicer actually, ah-ah...!, I help Users for Free on this Forum and your "Case" only took me a few Seconds..., but hum, you can always get me a Beer if you ever come to Amsterdam (NL), ah-ah...! :wink:
- (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: 6687
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Need help figuring out an If statement

by darklordofsith on Wed Jan 31, 2018 10:34 pm

Yes you're right that it's working and waiting one second, but after I ran the script I found that I need to wait slightly longer. Closer to 1.2-1.5 seconds for the page to load. I tried to play around with the z value that you listed and changed the z = 1 to z=2 and it started looking for and loading the second record on the page and then waiting 2 seconds. Is there a way for me to have it look for the first record and then wait x number of seconds (x being a number between 1.2 and 1.5 based on trial and error that I'm going to run).

Thanks so much for taking time to help me out. If not a beer, then I'll donate to a "Dumb novice programmers" support group in your name.
darklordofsith
 
Posts: 4
Joined: Wed Jan 31, 2018 9:34 am

Re: Need help figuring out an If statement

by chivracq on Wed Jan 31, 2018 11:05 pm

darklordofsith wrote:Yes you're right that it's working and waiting one second, but after I ran the script I found that I need to wait slightly longer. Closer to 1.2-1.5 seconds for the page to load. I tried to play around with the z value that you listed and changed the z = 1 to z=2 and it started looking for and loading the second record on the page and then waiting 2 seconds. Is there a way for me to have it look for the first record and then wait x number of seconds (x being a number between 1.2 and 1.5 based on trial and error that I'm going to run).

Thanks so much for taking time to help me out. If not a beer, then I'll donate to a "Dumb novice programmers" support group in your name.

Well, that's what I meant with "a second Var if you didn't like the [0-1] Values from '!VAR1' for the 'WAIT' Statement...".

With 2 Vars, your Script would then become stg like...:
Code: Select all
'Easy Access Vars:
SET Wait_Time 1.3

TAG POS=1 TYPE=BUTTON ATTR=TXT:Refresh
SET !TIMEOUT_STEP 0
SET !ERRORIGNORE YES
SET !EXTRACT_TEST_POPUP NO

'Check if Link  is there:
SET !EXTRACT NULL
TAG POS=1 TYPE=A ATTR=HREF:/requests/details/**** EXTRACT=TXT
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var z; if(s!='#EANF#'){z=1;} else{z=0;}; z;")
SET !VAR2 EVAL("var s='{{!EXTRACT}}', wt='{{Wait_Time}}'; var z; if(s!='#EANF#'){z=wt;} else{z=0.1;}; z;")

TAG POS={{!VAR1}} TYPE=A ATTR=HREF:/requests/details/****
WAIT SECONDS={{!VAR2}}
TAG POS={{!VAR1}} TYPE=SPAN FORM=NAME:NoFormName ATTR=TXT:Approve
TAG POS={{!VAR1}} TYPE=INPUT:RADIO FORM=NAME:NoFormName ATTR=NAME:status CONTENT=YES
TAG POS={{!VAR1}} TYPE=BUTTON ATTR=TXT:Call

You specify the Value that you want for 'Wait_Time' (like the "1.3" I gave it for example) that I have specified at the beginning of your Script for "easy Access" (and that Value is reused in '!VAR2' a bit further up...

I actually don't really "support" ""Dumb novice programmers" support groups" as "Dumb novice programmers" usually don't even try to read any Documentation nor find a Sol by themselves, Reason why I very rarely write Scripts for Users on this Forum and rather prefer to let/guide them to find a/the Solution themselves, you were a bit "lucky"... :wink:
But tja...!, if you are so "desperate" to throw your Money away, then yep, I can always drink a Beer to your Health, hum might be a good Idea after all, WE is coming, ah-ah...!, I have some PayPal Account associated to my 'gmail' Address: [My_Pseudo_on_the_Forum]@gmail.com 8)
Last edited by chivracq on Wed Jan 31, 2018 11:40 pm, edited 1 time in total.
- (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: 6687
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Need help figuring out an If statement

by darklordofsith on Wed Jan 31, 2018 11:27 pm

You're my hero, and I truly appreciate you taking time out to help me. Cheers!
darklordofsith
 
Posts: 4
Joined: Wed Jan 31, 2018 9:34 am

Re: Need help figuring out an If statement

by chivracq on Wed Jan 31, 2018 11:59 pm

darklordofsith wrote:You're my hero, and I truly appreciate you taking time out to help me. Cheers!

Ah-ah...!, you are even quicker to fire some PayPal Payment than me to write a Script, I'm "impressed"...:
Truly appreciate your help. You have no idea how many days I spent on the forum trying to figure that out myself. I might try and contact you for other help as it pops up, but I promise I won't try to abuse your goodwill and will help provide more beer money as needed. Thanks!

Well, Thanks in return, and the Amount is very generous I have to say, definitely good for a few Beers, ah-ah...! Grrr..., one more day to wait for the WE...! :twisted:

But hum, if you spent so much time trying to find a Sol on the Forum, you should have found a few of the Threads where I had already posted this or a very similar Sol, many times with Script included, even if like explained in my previous Post, I now tend to refrain from writing Scripts for Users that I rather try to "educate" and let them get more "literate" with iMacros for them to only need Help once or twice..., until they can "fly" by themselves, ah-ah...! (But if I didn't write the Script myself, I always encourage them to post their final Script if that can help other Users...)

But OK, dare to "shout" if you need Help again, on the Forum or you now have my E-mail Address... (But hum, I check the Forum more often than my own Mail Account, ah-ah...!) :wink:
- (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: 6687
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 5 guests

-->