Page 1 of 1

Tag elements in frames with changing frame numbers

Posted: Wed Jan 05, 2011 12:13 pm
by Tom, Tech Support
Do you need to tag an element on a frame, but the problem is you don't know which frame number to specify because it is always changing in the underlying source HTML?

The first recommendation is to use the NAME parameter of the FRAME command to specify the frame id rather than number. This is often more stable than using a frame number.

For example:

Code: Select all

But what if the frame doesn't have an identifier AND the number keeps changing? In this case, you can use some scripting code to create a loop that will iterate over frame numbers until the target element is found. It's a bit crude, but it's effective.

The following code snippet attempts to save an image which is located in a frame where the frame number is not known.

Code: Select all

Dim macroSaveImage
macroSaveImage = "CODE:"
macroSaveImage = macroSaveImage + "SET !TIMEOUT_STEP 1" + vbNewLine
macroSaveImage = macroSaveImage + "ONDOWNLOAD FOLDER=* FILE=box.png" + vbNewLine
macroSaveImage = macroSaveImage + "FRAME F={{loop}}" + vbNewLine
macroSaveImage = macroSaveImage + "TAG POS=1 TYPE=IMG ATTR=SRC:*.gif?* CONTENT=EVENT:SAVEPICTUREAS" + vbNewLine

Dim i
i = 0

	im.iimSet("loop", i)
	If im.iimPlay(macroSaveImage) = 1 Then
		Exit Do
	End If
	i = i + 1
This example assumes you are using VB script with the iMacros Scripting Edition, but the logic is essentially the same if you are using the built-in Javascript scripting interface with iMacros for Firefox:

Code: Select all

var macroSaveImage;
macroSaveImage =  "CODE:";
macroSaveImage +=  "SET !TIMEOUT_STEP 1" + "\n"; 
macroSaveImage +=  "ONDOWNLOAD FOLDER=* FILE=box.png" + "\n"; 
macroSaveImage +=  "FRAME F={{loop}}" + "\n"; 

var i = 0;

while (true)
   iimSet("loop", i)
   if (iimPlay(macroSaveImage) == 1)

Re: Tag elements in frames with changing frame numbers

Posted: Tue Jun 07, 2011 8:07 am
by Tom, Tech Support
You may have noticed an increasing trend for websites to use dynamically generated frame names, which also can't be used for reliable playback. For this reason, we enhanced the Expert click-mode in V7.36. Now when you record using the Expert click-mode inside of a frame, iMacros will by default record the frame name (if one exists), but it will also record a commented-out FRAME command that contains the frame number. If the frame name is random or dynamically generated each time by the website, then you have the option to edit your macro to use the frame number instead.