使用 iMacros 和 javascript 检查 html 元素是否存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16174655/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Check if html element exists with iMacros and javascript
提问by user2312194
I want to check if an HTML element exist with iMacros. If it does, I want to go to a URL. If not, I want to go to other URL.
我想检查 iMacros 是否存在 HTML 元素。如果是这样,我想转到一个 URL。如果没有,我想转到其他 URL。
Because iMacros doesn't have statements, I used javascript with the iMacros' EVAL. Here is the line that handles the javascript execution:
因为 iMacros 没有声明,所以我在 iMacros 的 EVAL 中使用了 javascript。这是处理 javascript 执行的行:
SET !VAR3 EVAL("var element = window.content.document.getElementById(\"some_element\");
if (typeof(element) != 'undefined' && element != null) {
var redirect = 'http://192.168.178.22/sc/report.php';
} else {
var redirect = 'http://192.168.178.22/sc/index.php?action=connect';
}
redirect;
")
*It's all in one line, but I formatted it for here.
*全部都在一行中,但我在此处对其进行了格式化。
Then, I will redirect with
然后,我将重定向
URL GOTO={{!VAR3}}
The problem is in both of the cases, the !VAR3 is set to 'undefined.'
问题是在这两种情况下,!VAR3 都设置为“未定义”。
I tried almost the same JS code on Firefox only, and it seems to be working.
我只在 Firefox 上尝试了几乎相同的 JS 代码,它似乎有效。
Windows 8 with the latest Firefox and the latest iMacros version.
装有最新 Firefox 和最新 iMacros 版本的 Windows 8。
Thank you.
谢谢你。
回答by macroscripts
var macro;
macro ="CODE:";
macro +="TAG POS=1 TYPE=DIV ATTR=CLASS:some_class CONTENT=EVENT:MOUSEOVER ";
var ret=null;
ret=iimPlay(macro);
if(ret>0)
{
//do something
}
else
{
//do something else
}
This would be the basic model of the script you want. You just have to insert the proper imacros code.
这将是您想要的脚本的基本模型。您只需要插入正确的 imacros 代码。