Home > Language Reference > Web Functions > ClickHTMLElement


The ClickHTMLElement function clicks on a web element within the current web page.


The ClickHTMLElement function clicks the element specified by its HTML descriptor and so will replay correctly even if the element has been moved within the web page. If the element is not an HTML element (Flash element, link in an image, ...), you can still automate a click using ClickOnTextOCR or ClickMouse functions.
You can specify a "right" parameter to right-click a web element. For a very small web element, if you see at replay that the click is not done on the exact small control, you can add mouse coordinates to ClickHTMLElement function.

Video: How to generate the ClickHTMLElement syntax and use its additional parameters.


ret=ClickHTMLElement(<html_descriptor> [, left|right|double [, <x>,<y>]])


<html_descriptor>, string, HTML descriptor of the HTML element to click within the current web page specified by the last UsePage. Use Recording mode to generate the ClickHTMLElement syntax.

left|right|double, optional keyword, left-click or right-click or double-click. The default is left-click.

<x>,<y>, optional integers, x, y coordinates relative to the specified element. It is used to click near the element.

Return value

Ret, optional numeric return code. If the specified HTML element has been successfully clicked 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 value (see Web Functions Error Codes).


ClickHTMLElement function does not return the actual link which is behind the clicked link. Use CopyLink function if you need the actual link.

At replay, the function waits for the specified HTML element to be loaded before clicking it. The timeout is the value of #ActionTimeout, so 30 secs by default.

You can use a variable for <html_descriptor> parameter : for example, to replace the words between the single quotes in ClickHTMLELement("A[INNERTEXT='Pacific Media']") with a variable, the code is:
a$="Pacific Media"
ClickHTMLElement("A[INNERTEXT= '"+a$+"']")

The "+a$+" are used to concatenate the first part of the html descriptor A[INNERTEXT='  with the last part '] and as they are strings, they must be surroounded by the double quotes "

When you write a script for capturing data, you usually use a loop for clicking each individual elements in order to go to the next page where the details for the clicked element has to be captured. Your list of elements to be clicked is usually stored in an array, and you build the clickhtmlelement line using array$(0), array$(1), ..., array$(i), ....

If array$(i) contains the ' character, the ClickHTMLElement will fail as the single quote is a separator for the clickhtmlelement syntax. So you need to replace the ' by the \' string (with the \ character in front of the ', the ' is not anymore understood as the separator). Below are a couple of lines demonstrating how to replace:
array$(i)="The O'Conors of Connacht and the O'Briens"
'Replace all the ' by \'
array$(i)=replace$(array$(i), "'","\'")
'Use now in the clickhtmlelement the correct HTML descriptor

If at replay you notice that the click is done before the element is displayed, use #HTMLPosRetry to slow down the click process.

If you need to click n times a link in a table, a link which is always the same word, the HTML descriptor uses the INDEX keyword to identify uniquely each link. For example if the word Document is the link to click on different rows of a table, the click on the first row will be:
ClickHTMLElement("A[INNERTEXT= 'Document']")
and the click on the link Document in the second row will be:
ClickHTMLElement("A[INNERTEXT= 'Document',INDEX='2']")
It is possible to iterate with such a loop:
        ClickHTMLElement("A[INNERTEXT= 'Document',INDEX='"+str$(i)+"']") 'note the concatenation : a single quote after INDEX,     
        'then double quote and the + concatenation sign
until i=10

See also

Handling inaccurate ClickHTMLELement


'Click Form link on www.wintask.com/demos page
UsePage("WinTask Demonstration Pages")
 ClickHTMLElement("A[INNERTEXT= 'Form']")

'Click Form link on www.wintask.com/demos page
UsePage("WinTask Demonstration Pages")
 ClickHTMLElement("A[INNERTEXT= 'Form']")

'Click Form link on www.wintask.com/demos page
UsePage("WinTask Demonstration Pages")
  ClickHTMLElement("A[INNERTEXT= 'Form']")