Check if html element exists with iMacros and javascript

user2312194 picture user2312194 · Apr 23, 2013 · Viewed 11.2k times · Source

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.

Answer

macroscripts picture macroscripts · Apr 24, 2013
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.