【问题标题】:Click a button if text exist in page with iMacros如果 iMacros 页面中存在文本,请单击按钮
【发布时间】:2012-05-09 23:38:54
【问题描述】:

我正在尝试使用 iMacros 和 Firefox 来单击取消关注按钮,前提是页面上存在此代码...

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

如果页面源中不存在上述内容,那么它将运行此 iMacros 代码...

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

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

EVAL("Javascript code here")

如果有人知道我该怎么做,我真的可以使用帮助

【问题讨论】:

  • 你的意思是“如果上面的 EXIST 在页面源中,那么它将运行这个 iMacros 代码......”,对吗?

标签: imacros


【解决方案1】:

你可以欺骗 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}}

【讨论】:

  • 我也遇到了类似的问题,现在我知道该怎么做了
【解决方案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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-05
    • 1970-01-01
    • 1970-01-01
    • 2014-06-25
    • 1970-01-01
    • 1970-01-01
    • 2020-01-11
    • 1970-01-01
    相关资源
    最近更新 更多