Click a button if text exist in page with iMacros

JasonDavis picture JasonDavis · May 10, 2012 · Viewed 28.2k times · Source

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

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

If the above does not exist in the page source then it would run this iMacros code...

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

From what I have read, there is no if/else type 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

Answer

symbiotech picture symbiotech · Nov 29, 2012

You can trick Imacros to make an If statement, but first you have to SET !ERRORIGNORE YES for 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}}