Click a button if text exist in page with iMacros

喜你入骨 提交于 2019-12-05 02:34:28

问题


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


回答1:


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}}



回答2:


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;
}


来源:https://stackoverflow.com/questions/10525640/click-a-button-if-text-exist-in-page-with-imacros

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!