Conditional execution of a line

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
zirjeo
Posts: 82
Joined: Fri Oct 28, 2016 1:49 am

Conditional execution of a line

Post by zirjeo » Sun Jun 18, 2017 2:50 am

IE 11, Windows 10, VERSION BUILD=11.5.498.2403

Basically trying to accomplish what looks like so many others on here have tried with no success, the task of skipping a line or executing a line only on certain conditions. So basically below I created a conditional that attempts to open a new tab only if the extracted text is less than 1 character in length otherwise do not open a new tab. You obviously cannot just put {{!VAR1}} on a line by itself as I have done below. Is there another way to go about this?

VERSION BUILD=11.5.498.2403
TAB T=1
SET !PLAYBACKDELAY 0.2
Set !EXTRACT_TEST_POPUP NO
TAG POS=1 TYPE=TH ATTR=TXT:Actions
TAG POS=R1 TYPE=SPAN ATTR=TXT: EXTRACT=TXT
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; if(s.length > 1){var x=\"\";}else{var x=\"TAB OPEN\";};")
{{!VAR1}}

It would also be cool if you could do something like this to get it to skip a line, having it place a ' in front of a line to comment it out, but also does not work...
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; if(s.length > 1){var x=\" ' \";}else{var x=\"\";};")
{{!VAR1}} TAB OPEN
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Conditional execution of a line

Post by chivracq » Mon Jun 19, 2017 2:10 am

zirjeo wrote:

Code: Select all

IE 11, Windows 10, VERSION BUILD=11.5.498.2403
Basically trying to accomplish what looks like so many others on here have tried with no success, the task of skipping a line or executing a line only on certain conditions. So basically below I created a conditional that attempts to open a new tab only if the extracted text is less than 1 character in length otherwise do not open a new tab. You obviously cannot just put {{!VAR1}} on a line by itself as I have done below. Is there another way to go about this?

Code: Select all

VERSION BUILD=11.5.498.2403
TAB T=1
SET !PLAYBACKDELAY 0.2
Set !EXTRACT_TEST_POPUP NO
TAG POS=1 TYPE=TH ATTR=TXT:Actions
TAG POS=R1 TYPE=SPAN ATTR=TXT: EXTRACT=TXT
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; if(s.length > 1){var x=\"\";}else{var x=\"TAB OPEN\";};")
{{!VAR1}}
It would also be cool if you could do something like this to get it to skip a line, having it place a ' in front of a line to comment it out, but also does not work...

Code: Select all

SET !VAR1 EVAL("var s='{{!EXTRACT}}'; if(s.length > 1){var x=\" [b]'[/b] \";}else{var x=\"\";};")
{{!VAR1}} TAB OPEN
"... what looks like so many others on here have tried with no success..."
=> Well, I have tried and I succeeded, ah-ah...! :twisted:
I only use '.iim' Macros (never used a '.js' Script) and I think my '.iim' Scripts go further in terms of Conditional Logic and "Artificial Intelligence" than anything I have ever seen on the Forum, you just need to be a little bit "Creative" ah-ah...! :oops:
Have a look for example at the following Thread where I explained a few of my "Techniques"...:
- Workarounds for Conditional Logic in Macro Code

But OK, your 'EVAL()' Statement is already using some Technique I use myself... which indeed will not work for a 'TAB OPEN' ah-ah...!, I have some Enhancement Request in the following Thread for a "Super" Built-in Variable that could contain other Commands:
- Feedback - Take the iMacros Add-on(s) Survey!
-14- Implement a "Super" Built-in Var that could contain Commands like 'OPEN' / 'CLOSE' / 'REFRESH' / 'CLEAR' / etc and other (Built-in) Vars like for example in '{{!COL{{!LOOP}}}}'.
:idea: => Would be nice if you could bump "my" Thread to show your "support" (you may review all other EnhReq's I have in that Thread of course, in case you find any other ones useful as well...!), I cannot get "things" implemented if I'm the only one asking, TechSup and Dev go "by the Number" of Users impacted/complaining/asking, ah-ah...! :idea:

But OK, back to your current "Case", I already have a Workaround for a "Conditional 'TAB CLOSE'", hum, you are on IE11 + v11.5, my Solution works for FF (v8.8.x + v8.9.x for FF, never tested on v9.x for FF, hum, I know already that it will probably not work anymore...), I've already asked several times if sbd could test that it work as well in other Browsers, nobody ever bothered to test/reply I think, I never tried/searched but I would think there must very probably be a very similar Solution for a 'TAB OPEN':
- Re: Any way of writing a macro that closes the entire browser?
But then I would think, it doesn't matter, fire the 'TAB OPEN' anyway, it doesn't matter, it's the 'TAB T=2' which matters and that you can easily make Conditional (I use it myself), and you can always use the Conditional 'TAB CLOSE' to close it if you want to "clean" your Tabs from your Macro, or use some 'TAB CLOSEALLOTHERS' from 'TAB_1' for example...

Your EnhReq for a "Conditional Comment" is a good Idea as well, I had never tried (I actually use a different Method to "mute" complete Sections of my Macros but a conditional Comment would indeed even be simpler, ah-ah...!, hum, could be "included" in "my" Super Built-in Var actually...), I will add it to my Thread of EnhReq's actually, after doing a little bit of Testing by myself...
But I think I already have some Workaround, a bit late now, but some of my Scripts are "Auto-Morphing", they are able to modify and recreate themselves, the "Concept" is a bit "complex" oops...!, so I'll have to think a bit how I do it again, ah-ah...! :oops:
Other Advanced User @iimfun posted once as well (maybe 1 year ago) some other (interesting...!) Method for generating "real" (Bookmarks) '.iim' Scripts on the fly using Base64 Encoding, was for iMacros for CR I think, but I guess it would work for FF as well... :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...
zirjeo
Posts: 82
Joined: Fri Oct 28, 2016 1:49 am

Re: Conditional execution of a line

Post by zirjeo » Mon Jun 19, 2017 3:19 am

Bumped your other post.

I thought about just letting it open the new tab, but then I have a few lines below it where I use PROMPT several times and I don't need the prompts either for the same conditions when I don't need a new tab. I have to keep hitting enter to get through the Prompts which is time and attention consuming when I'm running a long loop and trying to work on something else.

I had actually found the post of yours posted above and was looking through it the other day, but I didn't see anything that I could apply to what i'm trying to do. Maybe there is an answer in there and I just wasn't seeing it though.
zirjeo
Posts: 82
Joined: Fri Oct 28, 2016 1:49 am

Re: Conditional execution of a line

Post by zirjeo » Mon Jun 19, 2017 4:48 am

If you just do
PROMPT
it will skip over it when using SET !ERRORIGNORE YES and not pull up the prompt box, so I thought maybe I could set a conditional like below so {{!VAR1}} is blank and it would skip over it in the same way if needed but the prompt box pulls up anyhow unfortunately.

SET !VAR1 EVAL("var s='{{!EXTRACT}}'; if(s.length > 1){var x=\"\";}else{var x=\"Prompt info if length 1 or less\";};")
PROMPT {{!VAR1}}
iimfun
Posts: 239
Joined: Tue Jul 19, 2016 1:06 pm

Re: Conditional execution of a line

Post by iimfun » Mon Jun 19, 2017 6:39 am

chivracq wrote:@iimfun posted once as well (maybe 1 year ago) some other (interesting...!) Method for generating "real" (Bookmarks) '.iim' Scripts on the fly using Base64 Encoding, was for iMacros for CR I think, but I guess it would work for FF as well...
No, that solution for Chrome won't work for Firefox.


I think first of all @zirjeo should try whether the following command

Code: Select all

URL GOTO=javascript:window.open();void(0);
is valid in iMacros Browser 11.5.498.2403.
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Conditional execution of a line

Post by chivracq » Mon Jun 19, 2017 12:46 pm

zirjeo wrote:Basically trying to accomplish what looks like so many others on here have tried with no success, the task of skipping a line or executing a line only on certain conditions.
Hum..., wanted to add a Remark about that, is that iMacros by Design has been developed without any Conditional Commands... The "official" and "supported" way to add Conditional Behaviour to a Macro is to use a '.js' Script on FF or to use the Scripting Interface with iMB or any Browser...
zirjeo wrote:Bumped your other post.

I thought about just letting it open the new tab, but then I have a few lines below it where I use PROMPT several times and I don't need the prompts either for the same conditions when I don't need a new tab. I have to keep hitting enter to get through the Prompts which is time and attention consuming when I'm running a long loop and trying to work on something else.

I had actually found the post of yours posted above and was looking through it the other day, but I didn't see anything that I could apply to what i'm trying to do. Maybe there is an answer in there and I just wasn't seeing it though.
Yep, I saw the Bump, Thanks ah-ah...!
zirjeo wrote:If you just do
PROMPT
it will skip over it when using SET !ERRORIGNORE YES and not pull up the prompt box, so I thought maybe I could set a conditional like below so {{!VAR1}} is blank and it would skip over it in the same way if needed but the prompt box pulls up anyhow unfortunately.

SET !VAR1 EVAL("var s='{{!EXTRACT}}'; if(s.length > 1){var x=\"\";}else{var x=\"Prompt info if length 1 or less\";};")
PROMPT {{!VAR1}}
Hum, what you want is actually a Conditional (Input) 'PROMPT', then you may want to have a look at the following (long...!) Thread...:
- PROMPT Messagebox - Yes - No - Cancel (end)
iimfun wrote:
chivracq wrote:@iimfun posted once as well (maybe 1 year ago) some other (interesting...!) Method for generating "real" (Bookmarks) '.iim' Scripts on the fly using Base64 Encoding, was for iMacros for CR I think, but I guess it would work for FF as well...
No, that solution for Chrome won't work for Firefox.
Ah OK then, grrr...!

Thread I was referring to is this one, I think...:
- Re: Firefox Dev Edition imacro bookmarks and URLs don't work

And otherwise, the Technique to run/create a Macro from a Link could be used as well to conditionally create/run an embedded Macro on the fly, but hum..., I guess it will quickly become a bit cumbersome as that implies splitting the original Macro into several parts with some complex Workflow of different Sub-Macros calling each other, ah-ah...:
- Re: problem with using run.imacros.net to start a macro
iimfun wrote:I think first of all @zirjeo should try whether the following command

Code: Select all

URL GOTO=javascript:window.open();void(0);
is valid in iMacros Browser 11.5.498.2403.
Yep, exactly what I meant with:
... I never tried/searched but I would think there must very probably be a very similar Solution for a 'TAB OPEN'...
To "confirm", this Syntax works in both FCI's:
- iMacros for FF v8.8.2, PM v26.3.3 (=FF47), Win10-x64.
- iMacros for FF v8.9.7, FF54, Win10-x64.

It opens a New Tab and the Focus jumps automatically to that New Tab with no need for a 'TAB T=2' Command, and it works even if the Macro is run from a pinned Tab. iMacros though might get a bit "confused" at some point if it needs to get back to TAB_1, I didn't investigate...
Last edited by chivracq on Wed Aug 08, 2018 4:10 am, edited 1 time in total.
- (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...
zirjeo
Posts: 82
Joined: Fri Oct 28, 2016 1:49 am

Re: Conditional execution of a line

Post by zirjeo » Tue Jun 20, 2017 12:36 am

Ok these both work alone...

Code: Select all

URL GOTO=javascript:window.open("http://www.google.com");void(0);
URL GOTO=javascript:setTimeout("alert('TEST');",300);void(0);
But when I try to put them into EVAL, !VAR2 works but !VAR1 below does not work, it doesn't like 'TEST'. Do you know how I can tweak this to make it run? thanks

Code: Select all

SET !EXTRACT 1
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; if(s.length > 1){var x=\"\";}else{var x=\"javascript:setTimeout('alert('TEST');',300);void(0);\";};")
SET !VAR2 EVAL("var s='{{!EXTRACT}}'; if(s.length > 1){var x=\"\";}else{var x=\"javascript:window.open('http://www.google.com');void(0);\";};")
URL GOTO={{!VAR1}}
URL GOTO={{!VAR2}}
If I just do alert() the prompt comes up but it won't let me put anything inside ().
zirjeo
Posts: 82
Joined: Fri Oct 28, 2016 1:49 am

Re: Conditional execution of a line

Post by zirjeo » Tue Jun 20, 2017 1:29 am

This works inside EVAL..

javascript:setTimeout(function(){ alert('TEST'); }, 300);void(0);


Thanks a lot guys!
Post Reply