iMaros:FAQ

1.How to scroll down a page?
URL GOTO=javascript:window.scrollBy(0,20000)
 
2.string manipulation
String manipulation can be done by using EVAL or, if you are using the scripting interface, sending the text back to the calling script, manipulate it there, and then use it in the next macro:
 i = iim1.iimPlay ("GetText")
 s = iim1.iimGetExtract (1)
 
 'Manipulate s here!
 s = Mid(s, 3, 3)
 
 'Send s back to next macro
 i = iim1.iimSet ("myvar", s)
 'The macro UseNewText can use the new value with the {{myvar}} variable now
 i = iim1.iimPlay ("UseNewText")

3.pass variables from one macro to another
you can pass variables from one macro to another. The "trick" is to use the iimGetLastExtract command to return data (= any kind of extracted text or variable content) to the calling script:

(1) Store the values in !EXTRACT

Code: Select all
SET !EXTRACT {{!TAGX}}
SET !EXTRACT {{!TAGY}}
(2) In your calling script, retrieve the values via iimGetLastExtract

Code: Select all
x = iim1.iimGetLastExtract (1)
y = iim1.iimGetLastExtract (2)
(3) Set the new values for your next macro

Code: Select all
i = iim.iimSet ("valuex", x)
i = iim.iimSet ("valuey", y)
i = iim1.iimPlay ("nextmacro")
(4) Use these values in the next macro

Code: Select all
DS CMD=MOVETO X={{VALUEX}} Y={{VALUEY}}
 
4.access the DOM from iMacros for Firefox Javascript
var reportDataTable = window.document.getElementsByTagName("form")[0].getElementsByTagName("table")[0];
 
5.How to create nested loops?
VBS looping: http://wiki.imacros.net/VBS_looping
 
6.make the macro play a sound
URL GOTO=file://C:\Windows\Media\chimes.wav
 
7.Does the macro script wait for the page to fully finish loading?

On a few very complex web pages with frames the macro may continue before everything is loaded completely. In this case you can tell iMacros manually to wait for another "Page loaded..." signal by adding the WAIT SECONDS=#DOWNLOADCOMPLETE# command to the macro.
One solution that will always work is to use the IMAGESEARCH command to search for an image. iMacros will wait until this image appears (or the timeout value is reached). This approach looks at the website as if it were an image - just as a human would do! Thus this approach works with every web site, regardless of which web technology is used (HTML, Frames, ASP.NET, Java applet, Flash applet,....).
 
  • Run initial macro to visit some page (low !TIMEOUT as we don't want to wait for it to be fully loaded)
  • Run extraction macro in loop until keyword is found
var macro;
macro = "CODE:";
macro += "VERSION BUILD=6311226 RECORDER=FX" + " \n ";
macro += "TAB T=1" + " \n ";
macro += "SET !TIMEOUT 1" + "\n"
macro += "URL GOTO=http://iopus.com/" + " \n ";

iret = iimPlay(macro);

/* here comes the loop */
/* running as long as the keyword is not found*/
var loopcounter = 0;
while ( iimGetLastExtract().search("iMacros") == -1 )
{
   loopcounter ++;
   iimDisplay("Loop " + loopcounter);
   macro = "CODE:";
   macro +=  "SET !TIMEOUT_TAG 1" + "\n";
   macro +=  "FRAME F=0" + " \n ";
   macro +=  "TAG POS=1 TYPE=IMG ATTR=WIDTH:92&&VSPACE:6&&HEIGHT:14&&ALT:Highlights&&SRC:shared/images/home_highlight.gif&&TXT:" + " \n ";
   macro +=  "TAG POS=R1 TYPE=DIV ATTR=ALIGN:left&&TXT:iMacros<SP>is<SP>the* EXTRACT=TXT" + " \n ";
   iret = iimPlay(macro)   
}
 
 
9.  if I'm running some web testing and the page loaded generates a script error, I'd like that the error is recorded and maybe a screenshot taken for further investigation.
 
To create a screenshot, you can call the macro from within a script and call a second macro (consisting of only one line!) to take the screenshot.
 
i = iim1.iimPlay ("test macro")
if i < 0 then iimPlay ("CODE:SAVEAS TYPE=BMP FOLDER=* FILE=Time_{{!NOW:yyyymmdd_hhnnss}}.bmp")
 

posted on 2013-05-03 14:49  ibelieve  阅读(691)  评论(0编辑  收藏  举报

导航