Home > Web Automation Specific > HTML Descriptor

HTML Descriptor

WinTask x64 relies on each HTML element on a web page to be uniquely named in order to provide reliable playback of the automation script. Reliance on mouse coordinates could lead to unpredictable results as the web page layout changes, the browser window size changes, or the screen resolution is changed. By using the names of the web page elements, the automation script is said to be object-oriented. The script clicks a named link, enters text into a named field, clicks a named button, etc.

Each HTML element on a web page is referenced in an automation script by it's HTML Descriptor. Due to the complex format of an HTML Descriptor, a user typically enters Recording mode to generate the script statements that require an HTML Descriptor as an input parameter. HTML Descriptors can be copied but should not be changed indiscriminately. A modified HTML Descriptor will lead to the failure of the script during playback. For a description of the HTML Descriptor format, see article HTML Descriptor Advanced.

The following script was generated during Recording mode using IE browser. Comments have been added for clarity.

' Start Internet Explorer and load the Demonstration WinTask web site
    StartBrowser("IE", "www.wintask.com/demos")

' Wait for the web page to be loaded
    UsePage("WinTask Demonstration Pages")
' Click the "Page 2" link in the Products section on the left pane.
' The HTML Descriptor identifies the link element using the HTML A object
' and the INNERTEXT property. The name of the link element is specified
' between single quotes as the value of the INNERTEXT property.
   ClickHTMLElement("A[INNERTEXT= 'Page 2']")

' Wait for the clicked web page to be loaded
    UsePage("Page 2")    
' Enter the text "My Company" into the single line text field labeled "Your Company".
' The HTML Descriptor identifies the text element using the HTML INPUT
' object of type TEXT and the company property. The name of the text element
' is specified between single quotes as the value of the NAME property.
    WriteHTML(INPUT TEXT[NAME= 'company']", "My Company")    

' Enter the text "My Name" into the single text field labeled "Your Name"
' The HTML Descriptor identifies the text element using the HTML INPUT
' object of type TEXT and the name property. The name of the text element is specified
' between single quotes as the value of the NAME property.
    WriteHTML("TEXTAREA[NAME= 'name']", "My Name")

' Click the link labeled "here".
' The HTML Descriptor identifies the link element using the HTML
' A object and the INNERTEXT property. The name of the link element is specified
' between single quotes as the value of the INNERTEXT property.
   ClickHTMLElement("A[INNERTEXT= 'here']")

HTML Descriptors are also used by several WinTask x64 functions to read data from HTML elements on a web page. The CaptureHTML, CaptureTableHTML, and GetHTMLEditText functions are just a few of the functions that can read data from a web page. The easiest way to generate the appropriate script statements is to run the Capture Wizard (menu item Start/Capture Wizard) or the Spy tool (menu item Start/Spy). A complete example is given in article Capturing Data in a Web Page.

The following script was generated during Recording mode using the Capture Wizard. Comments have been added for clarity.

' Start Internet Explorer and load the Yahoo web site.
    StartBrowser("IE", "www.yahoo.com")
' Wait for the web page to be loaded.
    UsePage("Yahoo!")
' Capture the text that starts with "As of" from the "In the News" tab on the web page.
' The HTML Descriptor identifies the container element using the HTML DIV
' object and the CONTENT property. The text that identifies the desired
' container element is specified between single quotes as the value of the CONTENT property.
   ret = CaptureHTML("DIV[CONTENT= 'As']", captured_string$)
   MsgBox(captured_string$) ' Display captured text
'Note that the value of the CONTENT property must be the identical to the container element text at the time
'the automation script is executed. If the container element contains different text, or the HTML Descriptor is too specific, 
'the CaptureHTML function will fail to locate the element.


ret = CaptureHTML("DIV[CONTENT= 'As of 9:17 p.m. EST']", captured_string$)
    MsgBox(captured_string$) ' Display captured text

The script statement above will not replay correctly since it includes the time that the script was recorded. Use the Capture Wizard tool and its Content Validation dialog box to generate the correct HTML Descriptor for the CaptureHTML function. The value of the CONTENT property must specify a text string that does not change from one replay to another.


If you are accustomed to using HTML tags, or if you need to use variable HTML Descriptors, additional details on HTML Descriptors are given in article HTML Descriptor Advanced .


See also

Introduction
Web Synchronization
Web Advanced Synchronization
HTML Descriptor Advanced
How To Measure Response Time
Data Driven Automation