Click the button if text exists on the page with iMacros

I am trying to use iMacros with Firefox to click the UnFollow button ONLY if this code exists on the page ...

<small class="follow-status">follows you</small>

If the above does not exist in the page source, then it runs this iMacros code ...

TAG POS=1 TYPE=DIV ATTR=TXT:UnFollow

From what I read, there is no if / else syntax, but you can run Javascript with

EVAL("Javascript code here")

If anyone knows how I could do this, I could really use the help

+3
source share
2 answers

You can trick Imacros to make an If statement, but first you must SET !ERRORIGNORE YESfor this macro. Then:

SET EXTRACT NULL
'if this exist you extract the text(even if you know it)
'if doesn't exist should return error but we turned that off; Extract remains Null
TAG POS=1 TYPE=SMALL ATTR=TXT:follows<SP>you EXTRACT=TXT
SET !VAR1 EVAL("var text=\"{{!EXTRACT}}\"; if(text==\"follows you\") text = \"jibber\";else text = \"UnFollow\";text;")
'this one executes if the text is right, if not should give error but we turned that off
TAG POS=1 TYPE=DIV ATTR=TXT:{{!VAR1}}
+7
source

Use javascript file for this

run();
function run() {
  var exists = doesElementExist();
  alert('element exists? ' + exists);
  if (exists) {
    iimPlay('CODE: TAG POS=1 TYPE=DIV ATTR=TXT:UnFollow');
  }
  else {
    // do something else here
  }
}

// test if element exists
function doesElementExist() {
  iimDisplay('looking for small element with class "follow-status" on page');
  var code = iimPlay('CODE: SET !TIMEOUT_TAG 1\n'
                     + 'TAG POS=1 TYPE=SMALL ATTR=CLASS:follow-status EXTRACT=TXT');
  if (code !==1) {
    return false;
  }
  var extract = iimGetLastExtract();
  if (extract === '#EANF#') {
    return false;
  }
  return true;
}
+2
source

All Articles