I am new to JavaScript and I need some help with getting last extracted value from iMacros. The problem is that when I use JavaScript function alert()
, it shows correct last extract but then if conditional does not work.
Steps of macro:
Click on image which is positioned based on LOOP
Click on button and if there exists a text, extract the text and if text is 2 start another iim code. The code is more complex, this is only part for extract debug which is important for conditionals which starts another piece of code
The error I am getting is:
TypeError: path is undefined, line -633 (Error code: -991)
Here is the code:
var numPage = prompt("current numPage?");
numPage++;
var i = 1;
var macroStart;
macroStart = "CODE:";
macroStart += "'set global variables" + "\n";
macroStart += "SET !EXTRACT_TEST_POPUP NO" + "\n";
macroStart += "SET tabCheck NULL" + "\n";
macroStart += "SET !ERRORIGNORE YES" + "\n";
macroStart += "SET !EXTRACT NULL" + "\n";
macroStart += "SET !TIMEOUT_STEP 1" + "\n";
macroStart += "SET !CLIPBOARD NULL" + "\n";
macroStart += "SET productUrl {{!URLCURRENT}}" + "\n";
macroStart += "TAG POS={{i}} TYPE=IMG ATTR=SRC:https://www.xxx.sk/admin/xxx/xxx/img/uprav.gif" + "\n";
macroStart += "TAG POS=1 TYPE=A ATTR=ID:zalozka_obrazky" + "\n";
macroStart += "TAG POS=1 TYPE=A ATTR=TXT:2 EXTRACT=TXT" + "\n";
macroStartExtract = iimGetLastExtract();
if (macroStartExtract == 2) {
var goToProductUrl;
goToProductUrl += "'back to main product's page" + "\n";
goToProductUrl += "SET !VAR5 2" + "\n";
goToProductUrl += "PROMPT !VAR5" + "\n";
iimPlay(goToProductUrl);
} else {iimPlay(goToProductUrl);}
var macroChangePage;
macro2 = "CODE:"
macro2 += "TAG POS=2 TYPE=A ATTR=TXT:{{numPage}}"
while (i < 2) {
iimSet("i",i)
iimPlay(macroStart)
i++;
if (i == 2) {
iimSet("numPage", numPage)
iimPlay(macroChangePage)
numPage++
i = 1;
}
}
I checked the code for problems, I found that it was failing in the below block.
else {iimPlay(goToProductUrl);}
Since goToProductUrl variable is getting defined in the if condition. the if is not getting executed and when it enters the else block, the variable is undefined hence the program fails. Unable to check the program working due to lack of URL but should the else block be something like this?
else {iimPlay(macroStart);}
The javascript error is fixed, try building your code after removing the error.
var numPage = prompt("current numPage?");
numPage++;
var i = 1;
var macroStart;
macroStart = "CODE:";
macroStart += "'set global variables" + "\n";
macroStart += "SET !EXTRACT_TEST_POPUP NO" + "\n";
macroStart += "SET tabCheck NULL" + "\n";
macroStart += "SET !ERRORIGNORE YES" + "\n";
macroStart += "SET !EXTRACT NULL" + "\n";
macroStart += "SET !TIMEOUT_STEP 1" + "\n";
macroStart += "SET !CLIPBOARD NULL" + "\n";
macroStart += "SET productUrl {{!URLCURRENT}}" + "\n";
macroStart += "TAG POS={{i}} TYPE=IMG ATTR=SRC:https://www.xxx.sk/admin/xxx/xxx/img/uprav.gif" + "\n";
macroStart += "TAG POS=1 TYPE=A ATTR=ID:zalozka_obrazky" + "\n";
macroStart += "TAG POS=1 TYPE=A ATTR=TXT:2 EXTRACT=TXT" + "\n";
macroStartExtract = iimGetLastExtract();
if (macroStartExtract == 2) {
var goToProductUrl;
goToProductUrl += "'back to main product's page" + "\n";
goToProductUrl += "SET !VAR5 2" + "\n";
goToProductUrl += "PROMPT !VAR5" + "\n";
iimPlay(goToProductUrl);
} else {iimPlay(macroStart);}
var macroChangePage;
macro2 = "CODE:"
macro2 += "TAG POS=2 TYPE=A ATTR=TXT:{{numPage}}"
while (i < 2) {
iimSet("i",i)
iimPlay(macroStart)
i++;
if (i == 2) {
iimSet("numPage", numPage)
iimPlay(macroChangePage)
numPage++
i = 1;
}
}