Conditional steps

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
dyneck
Posts: 7
Joined: Sun Mar 13, 2016 4:51 pm

Conditional steps

Post by dyneck » Sun Mar 20, 2016 7:48 pm

VERSION BUILD=8350307
Windows XP
Chrome 49.0.2623.87

It continuation of my topic -> http://forum.imacros.net/viewtopic.php?t=25948#p68323
I decided to write my script for Chrome because quick repeating (using loop 'for')this one written in javascript leads to freeze of Firefox.
Javascript doesn't work in iMacros for Chrome so I used this EVAL solution.

But I wonder how to use it in case if I have some more steps to do (not only playing sound alert) when some element is displayed at website.
In Javascript solution which I linked above I would add more steps to script which is run inside 'if' condition.

Using EVAL I wrote it like this:
SET !ERRORIGNORE YES
SET !EXTRACT_TEST_POPUP NO

TAB T=1
SET !TIMEOUT_STEP 1
URL GOTO=xxx
TAG XPATH="/html/body/div[2]/div/div[4]/div/div[1]/div[6]/div[2]/div[2]/div/div[3]/div/table/tbody/tr[1]/td[1]" EXTRACT=TXT

SET !VAR1 EVAL("if('{{!EXTRACT}}'!='#EANF#'){var s='/C:/police.wav';}s;")
SET !VAR2 EVAL("if('{{!EXTRACT}}'!='#EANF#'){var s='\"/html/body/div[2]/div/div[4]/div/div[1]/div[6]/div[2]/div[2]/div/div[3]/div/table/tbody/tr[1]/td[3]/select\"';}s;")
SET !VAR3 EVAL("if('{{!EXTRACT}}'!='#EANF#'){var s='Add<SP>to<SP>basket';}s;")
SET !VAR4 EVAL("if('{{!EXTRACT}}'!='#EANF#'){var s='3';}s;")

TAG XPATH={{!VAR2}} CONTENT=%2
TAG POS=1 TYPE=SPAN ATTR=TXT:{{!VAR3}}
WAIT SECONDS={{!VAR4}}
URL GOTO=file://{{!VAR1}}
I wonder it is possible to write it somehow shorter, simpler and quicker without using four variables for each step which I wan't to execute if some element is present at the website.
chivracq
Posts: 8929
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Conditional steps

Post by chivracq » Sun Mar 20, 2016 9:50 pm

dyneck wrote:

Code: Select all

VERSION BUILD=8350307
Windows XP
Chrome 49.0.2623.87
It continuation of my topic -> http://forum.imacros.net/viewtopic.php?t=25948#p68323
I decided to write my script for Chrome because quick repeating (using loop 'for')this one written in javascript leads to freeze of Firefox.
Javascript doesn't work in iMacros for Chrome so I used this EVAL solution.

But I wonder how to use it in case if I have some more steps to do (not only playing sound alert) when some element is displayed at website.
In Javascript solution which I linked above I would add more steps to script which is run inside 'if' condition.

Using EVAL I wrote it like this:

Code: Select all

SET !ERRORIGNORE YES
SET !EXTRACT_TEST_POPUP NO

TAB T=1
SET !TIMEOUT_STEP 1
URL GOTO=xxx
TAG XPATH="/html/body/div[2]/div/div[4]/div/div[1]/div[6]/div[2]/div[2]/div/div[3]/div/table/tbody/tr[1]/td[1]" EXTRACT=TXT
 
SET !VAR1 EVAL("if('{{!EXTRACT}}'!='#EANF#'){var s='/C:/police.wav';}s;")
SET !VAR2 EVAL("if('{{!EXTRACT}}'!='#EANF#'){var s='\"/html/body/div[2]/div/div[4]/div/div[1]/div[6]/div[2]/div[2]/div/div[3]/div/table/tbody/tr[1]/td[3]/select\"';}s;")
SET !VAR3 EVAL("if('{{!EXTRACT}}'!='#EANF#'){var s='Add<SP>to<SP>basket';}s;")
SET !VAR4 EVAL("if('{{!EXTRACT}}'!='#EANF#'){var s='3';}s;")

TAG XPATH={{!VAR2}} CONTENT=%2
TAG POS=1 TYPE=SPAN ATTR=TXT:{{!VAR3}}
WAIT SECONDS={{!VAR4}}
URL GOTO=file://{{!VAR1}}
I wonder it is possible to write it somehow shorter, simpler and quicker without using four variables for each step which I wan't to execute if some element is present at the website.
Well..., no, that's more or less the way to do it in pure '.iim'... You have 1 Conditional Sound, 1 Conditional 'WAIT' and 2 Conditional Select/Click, you need 4 'EVAL()' Statements to spit out the Values that you need...

I don't use 'XPATH', always 'POS=n', usually 'POS=1', and I usually turn my 'EVAL()' Statements to spit out a "1" / "0" to use for the 'POS=n' and if there are several Conditional 'TAG' Statements, they can very often reuse the same Var, or depend on each other using Relative Positioning.

What is the Reason that you use 'XPATH' btw...? In the 3 years that I've been active on the Forum, it's the 2nd time I see sbd using 'XPATH'...
I wouldn't know how to identify it, except from using the EVENT Mode without ID's which uses 'XPATH', I reckon... :oops:
- (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