Home > Language Reference > Web Functions > WriteHTML

WriteHTML

The WriteHTML function writes text in a text field web-form.

Usage

Used to fill automatically a form; the data can be retrieved from an Excel file, an Ascii file, an ODBC database, or just from Clipboard.

Video: WriteHTML writes some text into a field within a web form. WriteHTMLEncrypted and WriteHTMLPaste are variations and the video explains the use of those three WinTask functions.

Syntax

ret=WriteHTML(<html_descriptor> , <text>)

Parameters

<html_descriptor>, string, HTML descriptor of the text field. Use Recording mode to generate the WriteHTML syntax.

<text>, string, text to write in the form field. If the text includes special characters (for instance a <), use WriteHTMLPaste function instead of WriteHTML function.

Return value

Ret, optional numeric return value. If the function succeeds writing within 30 seconds (this default value can be changed using #ActionTimeout), the function returns 0. If the function fails, the return value is a nonzero negative value (see Web Functions Error Codes).

Remarks

If the web-form field is already filled, WriteHTML for INPUT TEXT tag deletes first the content and writes the specified string. If you want 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

WriteHTMLPaste
WriteHTMLEncrypted
#HTMLPosRetry

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()

'On the demonstration WinTask Web site loaded in Chrome, we click the Form link and then we fill the form:
StartBrowser("CH", "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.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.

StartBrowser("IE", "www.wintask.com/demos")
UsePage("WinTask Demonstration Pages")
ClickHTMLElement("A[INNERTEXT= 'Form']")

'Now we can fill the form in a loop
i=0
repeat
    UsePage("Form")
    WriteHTML("INPUT TEXT[NAME= 'company']", data$(i))
    ClickHTMLElement("INPUT RESET[VALUE= 'Clear']")     
    i=i+1
until data$(i)=""