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 <), keyboard mnemonics must be used ; Recording mode generates them for you.

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

-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, use "" as for instance :
WriteHTML("INPUT TEXT[NAME='first_name']","")
BUT 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 then <BackSpace> keyboard mnemonic as for instance:
WriteHTML("TEXTAREA[NAME= 'steps']", "<BackSpace><BackSpace><BackSpace><BackSpace><BackSpace><BackSpace>")

 
WriteHTML function cannot send as is keyboard mnemonics such as <Alt <Enter>>, you need to use the keyboard mnemonics for the string to send, "normal text"+"<Alt <Enter>>"+"normal text".

See also

#HTMLPosRetry

Examples

On WinTask Web site, we click the menu item Free Downloads on the left:

StartBrowser("IE","www.wintask.com")

UsePage("WinTask - Automation software and Task Scheduler. Macro software with Macro Recorder")

ClickHTMLElement("A[INNERTEXT= 'Free Downloads']")

 

UsePage("WinTask - FREE 30 Day Trial Offer")

ClickHTMLElement("INPUT CHECKBOX[NAME= 'tutorial']")

WriteHTML("INPUT TEXT[NAME= 'organization']", "taskware")

WriteHTML("INPUT TEXT[NAME= 'last_name']", "Mercer")

WriteHTML("INPUT TEXT[NAME= 'email']", "test@test.com")

WriteHTML("INPUT TEXT[NAME= 'sources']", "wintask")

ClickHTMLElement("INPUT SUBMIT[VALUE= 'Start Download']")

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"
'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+1

until data$(i)=""