QUESTION: Why is my attempt at passing a variable from the .js to the iim macro file not working?
I have the following two files:
test.js:
for (var1 = 100; var1 <= 200; var1 = var1 + 50)
{
iimSet("var1",var1);
iimPlay("test2");
}
test2.iim
VERSION BUILD=9030808 RECORDER=FX
TAB T=1
SET !TIMEOUT_PAGE 1
SET !ERRORIGNORE YES
URL GOTO=javascript:document.getElementsByClassName("scroll_element")[0].scrollBy(0,var1)
WAIT SECONDS=3
What the scripts should do: In the previous example, I am attempting to call test.js which in turn calls test2.iim to scroll down on a specific website a few times.
in the file test2.iim, I attempt to use var1 in the second last line to scroll down a certain element in a specific div. It does not work. HOWEVER, if I replace var1 with 100 like so:
URL GOTO=javascript:document.getElementsByClassName("scroll_element")[0].scrollBy(0,100)
It does work, and 100 pixels are scrolled down. This leads me to believe that var1 was not passed for some reason, though I though that my implementation of
iimSet("var1",var1);
was appropriate.
Does anyone know what I did wrong?
First, using "var1" is not a good idea, as it has almost the same name as the internal !var1 variable. I am not sure if this is causing an issue, but better avoid it. But the main issue is the missing {{...}}. For example, if you use "myvar1" as variable, then you need to use {{myvar1}} inside the macro:
URL GOTO=javascript:document.getElementsByClassName("scroll_element")[0].scrollBy(0,{{myvar1}})