Tag elements in frames with changing frame numbers

Share your tips, tricks and favorite iMacros macros, scripts and applications for web automation in general here.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team
Post Reply
Tom, Tech Support
Posts: 3834
Joined: Mon May 31, 2010 4:59 pm

Tag elements in frames with changing frame numbers

Post by Tom, Tech Support » Wed Jan 05, 2011 12:13 pm

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

FRAME NAME=main3
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:http://www.phprocket.com/images/offsite/iMacros/TestFrames/images/*.gif?* CONTENT=EVENT:SAVEPICTUREAS" + vbNewLine

Dim i
i = 0

Do
	im.iimSet("loop", i)
	If im.iimPlay(macroSaveImage) = 1 Then
		Exit Do
	End If
	i = i + 1
Loop
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"; 
macroSaveImage +=  "TAG POS=1 TYPE=IMG ATTR=SRC:http://www.phprocket.com/images/offsite/iMacros/TestFrames/images/*.gif?* CONTENT=EVENT:SAVEPICTUREAS" + "\n"; 

var i = 0;

while (true)
{
   iimSet("loop", i)
   if (iimPlay(macroSaveImage) == 1)
   {
      break;
   }
   i++
}
Regards,

Tom, iMacros Support
Tom, Tech Support
Posts: 3834
Joined: Mon May 31, 2010 4:59 pm

Re: Tag elements in frames with changing frame numbers

Post by Tom, Tech Support » Tue Jun 07, 2011 8:07 am

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.
Regards,

Tom, iMacros Support
Post Reply