0

I have just joined on here and am still learning imacros and java so apologies if I seem a little slow ! I currently have this code in imacros to check an element for a certain value , and then to do workarounds in java:

TAG POS=1 TYPE=P ATTR=TXT:* EXTRACT=TXT
SET !VAR2 EVAL("var s=\"{{!EXTRACT}}\"; if(s.match(\"error\")){url=\"imacros://run/?m=#Current.js\";} else url=\"imacros://run/?m=#Current2.iim\"; url;")
URL GOTO={{!VAR2}}

I know its not fantastically optimised but it works. But heres the new problem. I need to do it again on a different element that isnt always there . So how do I go about that ? This is the relevant imacros line...

TAG POS=1 TYPE=SPAN ATTR=TXT:Click

So yeah I need to extract it and compare like the first example , but like I say, its only there about 20-30% of the time . So it needs to be checked to see if it exists , if it does then run the if else , and if not then to continue as normal .

Thanks in advance guys !

If there is a more efficient way of doing things in the first example then that would be great too because I am aware that its bloaty , and makes FF hog more memory

And yes I've searched and saw this :

Check if html element exists with iMacros and javascript

and this:

Check if element exists in jQuery

But I am still confused and overwhelmed because I am quite new to js.....

Community
  • 1
  • 1

1 Answers1

0

First of all you should read the wiki info as to the JavaScript Scripting Interface in 'iMacros for Firefox'.
Afterwards take a look at js-scripts in the default 'Demo-Firefox' folder.

In order to understand that principle better, here is how your first code may look like:

iimPlayCode("TAG POS=1 TYPE=P ATTR=TXT:* EXTRACT=TXT");

var s = iimGetExtract();
if (s.match("error")) {
    // not good idea to run 'js' from 'js' scripts
    iimPlayCode("URL GOTO=imacros://run/?m=#Current.js");
} else {
    // it's alright here
    iimPlay("#Current2.iim");
}
Shugar
  • 5,269
  • 1
  • 9
  • 9
  • Thanks for the answer , I have implemented it that way now, but can you give me any advice on the latter half of the question ? – FadeToBlack Nov 26 '16 at 22:57