Click a button if text exist in page with iMacros

2020-06-25 01:37发布

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

标签: imacros
2条回答
乱世女痞
2楼-- · 2020-06-25 02:05

Use a 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;
}
查看更多
你好瞎i
3楼-- · 2020-06-25 02:09

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}}
查看更多
登录 后发表回答