简体   繁体   中英

Check if html element exists with iMacros and javascript

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM