Check if html element exists with iMacros and javascript

℡╲_俬逩灬. 提交于 2019-12-31 02:29:18

问题


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.

Because iMacros doesn't have statements, I used javascript with the iMacros' EVAL. Here is the line that handles the javascript execution:

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.'

I tried almost the same JS code on Firefox only, and it seems to be working.

Windows 8 with the latest Firefox and the latest iMacros version.

Thank you.


回答1:


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.



来源:https://stackoverflow.com/questions/16174655/check-if-html-element-exists-with-imacros-and-javascript

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