The TAG command selects HTML elements from the current website. The identification of the element is given by providing the parameters POS, TYPE, FORM and ATTR. If the selected element is a link, the link is followed, i.e. the TAG command acts as if it clicks on the element. If the selected element is part of an input form, the CONTENT parameter can be used to fill content into the selected field.
For the TYPE, FORM and ATTR parameter sub-parameters are used. Sub-parameters are used in the form
parameter=sub-parameter:value.
Especially in the ATTR parameter extensive use of the wildcard * can be made.
Following links
To follow links, the TYPE parameter of the TAG command is set to A. For text links the FORM parameter is not needed. Which link will be followed is solely determined by the POS and the ATTR parameter. Except for the number of occurence on the page (determined by the POS parameter), a link is uniquely identified by its name and its URL. Therefore, the ATTR parameter offers two different sub-parameters: TXT and HREF. To select a link by its name, use
ATTR=TXT:some_name,
to select by its URL, use
ATTR=HREF:some_url.
Sometimes iMacros continues with a TAG command inside a frame before the web site in that frame has been completely loaded. This can be avoided by adding a WAIT SECONDS=#DOWNLOADCOMPLETE# command before the TAG command.
Filling forms
On one webpage several forms can appear, therefore the FORM parameter determines which form to use by its NAME sub-parameter. The input type is selected using the TYPE parameter, if neccessary with the sub-parameter INPUT.
Special TAG Commands for Drop Down Menus
The CONTENT parameter is used to specify which element of a drop down menu (generated by the HTML SELECT command) is selected. By default, the CONTENT parameter of TYPE=SELECT stores the position in the list (also called index) of the selected value. This typically looks like this
TAG TYPE=SELECT FORM=NAME:form1 ATTR=NAME:select1 CONTENT=1
You can manually change this so that an entry is selected by its name or its value. The name of the menu item is the text which is displayed in the drop down menu. The value is the text that follows the VALUE= parameter in the OPTION tag. To select an entry by its name, add a $ before the name so that the command looks like
TAG TYPE=SELECT FORM=NAME:form1 ATTR=NAME:select1 CONTENT=$Apple
To select an entry by its value, use the percent symbol (%)
TAG TYPE=SELECT FORM=NAME:form1 ATTR=NAME:select1 CONTENT=%AP
Spaces must be written as <SP>. The comparison in the latter two cases is case insensitive and wildcards can be used.
In multiple selection menus, multiple selection can be achieved by listing indices separated by a colon (:). To select all values of a selection, use CONTENT=ALL.
If you start the macro via iimPlay and select a value that is NOT in the selection, the iimPlay command returns an error code that is the maximum number of lines possible.
Hidden Input
Hidden input fields are used in HTML to write information (like usernames are session IDs) in the HTML code so that the user does not have to type them in manually every time a new page is loaded. Since hidden fields are not displayed in the browser, the TAG command for them cannot be generated during normal recording. But you can add TAG commands with TYPE=HIDDEN manually into the macro and iMacros will fill these hidden fields during replay. To do this, record an TAG command for a visible field (e.g. the name input field) and you get:
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:TestForm ATTR=NAME:Name CONTENT=Peter
To modify this for the hidden field we change the TYPE from INPUT:TEXT to INPUT:HIDDEN and the name from Name to abc:
TAG POS=1 TYPE=INPUT:HIDDEN FORM=NAME:TestForm ATTR=NAME:abc CONTENT=999999
File Upload
Internet Explorer and other browsers do not allow automatic filling of any fields with the type FILE. Typically these fields are used for uploading files. However, iMacros can work around this limitation with the WINCLICK statement. More details can be found in the "Demo-FileUpload" macro.
Triggering events
Sometimes it is required to fire certain events concerning a web site element characterized by the parameters in the TAG command. To fire an event, set EVENT:#event_name as the CONTENT parameter. Currently, two events are supported, SAVEITEM and MOUSEOVER.
SAVEITEM
This event can be used to save items, mostly images, from any web site. A command doing this is most easily compiled by using the Save Item Wizard or clicking on the elements during record and adding CONTENT=EVENT:#SAVEITEM manually. To control the location and name of the downloaded file, use the ONDOWNLOAD command.
SAVEPICTUREAS
The command is named after the corresponding functions in the Internet Explorer menu, "Save Picture as". You can right-click on any web page element to see if the web page element supports this feature. To create such a command, you have to click on the elements during record and add CONTENT=EVENT:#SAVEITEM manually. To control the location and name of the downloaded file, use the ONDOWNLOAD command.
SAVETRARGET
The command is named after the corresponding functions in the Internet Explorer menu, "Save Target as". You can right-click on any web page element to see if the web page element supports this feature. To create such a command, you have to click on the elements during record and add CONTENT=EVENT:#SAVEITEM manually. To control the location and name of the downloaded file, use the ONDOWNLOAD command.
MOUSEOVER
For the selected element a mouseover event is triggered. This is sometimes needed to change the state of an image.
FAIL_IF_FOUND
This event is an iMacros internal event as oppose to an HTML event. It is useful when doing keyword searches.
Syntax
TAG POS=n TYPE=type [FORM=form] ATTR=attr [CONTENT=some_content]
Parameters
POS
Specifies the number of the occurence of the HTML element. By default, the occurence is counted from the top of the page. But using "POS=Rx" the occurence can also be relative to the previous TAG command (see Relative Extraction for more details on this concept.)
TYPE
Specifies the HTML type of the element
FORM
Specifies the name of the parent FORM element (only valid for FORM child elements).
ATTR
Specifies the identifier for the selected element.
CONTENT
Specifies the content to send to the selected element (only valid for FORM child elements).
Examples
See any of the example demos in the Macros\ directory of your iMacros installation.
See Also
FRAME, TAB, EXTRACT, CLICK, WINCLICK, BACK, URL
Page URL http://www.iopus.com/imacros/help/cmd_tag.htm