ClickHTMLElement
Web function.
The ClickHTMLElement function clicks a specified html element in the current Web page.
Usage
Used to click a Web control on a Web page. The ClickHTMLElement function is object-oriented (compared to ClickMouse function) and will replay correctly even if the control has been moved within the Web page. Using the "right" parameter, you can open the context menu for the specified Web control. For a very small Web control, if you see at replay that the click is not done on the exact small control, you can add mouse coordinates to ClickHTMLElement function.
Syntax
ret=ClickHTMLElement(<html_descriptor> [,left|right[,<x>,<y>]])
Parameters
<html_descriptor>, unique identifier for the HTML element to click within the current Web page specified by the last UsePage. See HTML descriptor for each HTML objects identification. Use Recording mode for generating automatically the ClickHTMLElement syntax, you can use too Spy for finding the HTML descriptor for block-text objects.
left|right, optional mouse button ; if not specified, a left click is used.
<x>,<y>, optional, mouse coordinates relative to the clicked element : it can be used for clicking slightly besides the element.
Return value
Ret, 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. 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
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 ']"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
ClickHtmlElement("A[INNERTEXT='"+array$(i)+"']")
Example
On WinTask Web site, we click the Free Downloads link in the menu 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']")
CloseBrowser()