WriteHTML
Web function.
The WriteHTML function writes text in a Web form.
Usage
Used mainly to fill automatically a form ; the data to write can be retrieved from an Excel file, an Ascii file, an ODBC database, or just from Clipboard.
Syntax
ret=WriteHTML(<html_descriptor>,<text>)
Parameters
<html_descriptor>, unique identifier for the HTML object where to write within the current Web page specified by the last UsePage. See HTML descriptor for HTML tags identification. Use Recording mode for generating automatically the WriteHTML syntax.
<text>, string, text to be typed in the form control. If the string includes special characters (for instance a <), use WriteHTMLPaste function instead of WriteHTML.
Return value
Ret, numeric return code. The function tries to find the HTML object for 30 seconds (this default value can be changed using #ActionTimeout), and then types the text. If the object has been found, the function returns 0. Otherwise use this return code for Error Handling.
List of negative error codes
-1
No browser in use (no previous UsePage or StartBrowser)
-3
Bad descriptor, invalid syntax
-4
The browser has been lost (for instance because of a Closewindow)
-5
Page not found
-8
Specified element not found
-11
Any other error
-14
Invalid character sent by WriteHTML - use instead WriteHTMLPaste function
-404,405
Usual http error codes (requires IE 6 or above)
Remarks
If the field in the Web form is already filled, WriteHTML for INPUT TEXT tag deletes the content and writes the string specified by the function. If you need to force the the content deletion without typing any new text, use "" as for instance :
WriteHTML("INPUT TEXT[NAME='first_name']","")
WriteHTML for TEXTAREA tag (multiple lines for the text) writes the specified string where the current cursor is (or a the end of the existing characters if the text cursor is not within the field). If you need to force the content deletion, use WriteHTMLPaste function with the Delete keyword.
If at replay, you see that the text is not typed correctly, slow down the field filling using #HTMLPosRetry.
See also
Examples
On the demonstration WinTask Web site, we click the Form link and then we fill the form:
StartBrowser("IE", "www.wintask.com/demos")
UsePage("WinTask Demonstration Pages")
ClickHTMLElement("A[INNERTEXT= 'Form']")
UsePage("Form")
WriteHTML("INPUT TEXT[NAME= 'company']", "My Company")
ClickHTMLElement("INPUT RESET[VALUE= 'Clear']")
CloseBrowser()
Fill a form using values read in an Excel file:
' We need to populate an array reading the values in the Excel file. First line in the script must be the declaration of the array
Dim data$(100)
'Read the excel file
fileexcel$="myexcelfile.xls" ' If you use Excel 2007, the extension is xlsx
'In data$ array, we store the content of the cells from A1 to A100
ReadExcel(fileexcel$,"A1:A100", data$())
'data$(0) contains A1 cell, data$(1) contains A2 cell and so on.
'Now we can fill the form in a loop
i=0
repeat
UsePage("My Web Form")
WriteHTML("INPUT TEXT[NAME= 'q']", data$(i))
i=i+1until data$(i)=""