TAG

From iMacros

Jump to: navigation, search

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 then 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 then 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.

(For more background information on how TAG is related to the HTML source code, visit TAG parameters explained)

The TAG command also incorporates the EXTRACT functionality of iMacros, post Version 6.0. Giving an additional EXTRACT parameter to idenitify the type of extraction to perform.

Contents

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 the 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 (:).

TAG TYPE=SELECT FORM=NAME:form1 ATTR=NAME:select1 CONTENT=$Apple:$*berry*:$Peach 
TAG TYPE=SELECT FORM=NAME:form1 ATTR=NAME:select1 CONTENT=1:3:8 

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 then the iimPlay command returns an error code that is the maximum number of lines possible. For an example, please see this forum post: Number of Options in a Select tag.

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 a 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.

  • 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.
  • SAVETARGET
    The command is named after the corresponding function 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 occurrence of the HTML element. By default the occurence is counted from the top of the page. But using "POS=Rx" the occurrence 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).
    (Replace blank spaces by <SP>, like in "Hello<SP>world")
  • EXTRACT
    Specified the type of extraction to be carried out

The EXTRACT Parameter

Extracts data from websites. Use the attribute ATTR to determine which part is to be extracted. Normally this part is generated by the Extraction Wizard. The EXTRACT command searches the HTML source code of the website for the nth occurence of ATTR and extracts it. The ATTR must always end with a wildcard *.

If several EXTRACT commands appear in one macro the results are separated by the string [EXTRACT]. This string is automatically translated into a line break when using the "SAVEAS TYPE=EXTRACT" command.

If complete tables were extracted then adjacent table elements are separated by the string #NEXT# and ends of table rows are delimited by the string #NEWLINE#. These tags are automatically translated into commas and newlines when you use the "SAVEAS TYPE=EXTRACT" command.

  • The following values may be specified in the EXTRACT parameter of a TAG command.
    • TXT
      Plain text extraction, all HTML tags are taken out.
      When used with a drop-down list (select element), it extracts the selected (visible) entry.
    • TXTALL
      For use with a drop-down list (select element). It extracts all entries of the list.
    • HTM
      The full HTML of the element the extraction anchor points to.
    • HREF
      The URL of the page element the extraction anchor points to.
    • TITLE
      The title of the page element the extraction anchor points to.
    • ALT
      The alternative text of an image the extraction anchor points to.

When extracting text from input boxes (TAG command contains "TYPE=INPUT"), there must not be a "CONTENT" parameter. Cf. the FAQ: How do I extract the content of an Input Box?

Examples

See any of the example demos in the Macros\ directory of your iMacros installation.


TAGs and HTML

A general information about the relation between the HTML source code and the TAGs that work on this code, can be found here: TAG parameters explained (older version: TAGs_and_HTML)

See Also

FRAME, TAB, CLICK, WINCLICK, BACK, URL, TAG parameters explained

Retrieved from "http://wiki.imacros.net/TAG"