如果页面中存在包含iMacros的文本,请单击按钮

时间:2012-05-09 23:38:55

标签: imacros

如果页面上存在此代码,我正在尝试使用iMacros与Firefox单击UnFollow按钮...

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

如果页面源中不存在上述内容,则会运行此iMacros代码...

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

根据我的阅读,没有if / else类型语法,但您可以使用

运行Javascript
EVAL("Javascript code here")

如果有人知道如何做到这一点我真的可以使用帮助

2 个答案:

答案 0 :(得分:7)

你可以欺骗Imacros制作一个If语句,但首先你需要SET !ERRORIGNORE YES这个宏。然后:

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

答案 1 :(得分:2)

使用javascript文件

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