Home > Running a Script > Handling Errors & Logging > Handling Inacurrate ClickHTMLElement

Handling Inacurrate ClickHTMLElement

At times you may come across an error message generated by a WinTask function that failed because a preceding ClickHTMLElement function did not execute correctly. As you watch the script execute, you see the mouse cursor click somewhere on the web page, but not on the intended element.

One possible cause for this error is that the script was attempting to click a small hyperlink but the default mouse click coordinates are inaccurate. The solution is to use the optional parameters of the ClickHTMLElement function to pinpoint the mouse click coordinates.

Click slightly to the right and down from the top-left corner of the HTML element:
ClickHTMLElement("A[INNERTEXT= 'Top 10 Uses']",left,5,5)

Another cause for this error is that the HTML Descriptor specified in the ClickHTMLElement statement clicks an unintended element. This is usually caused by two or more elements on the web page that produce the same HTML Descriptor during recording mode. Try to use Navigate function instead of ClickHTMLElement: the Navigate function goes directly to the url instead of replaying the click on the hyperlink.

The following code illustrates how a ClickHTMElement statement can be replaced with a Navigate statement.
'Original code generated during Recording Mode
StartBrowser("IE", "www.wintask.com/demos")
UsePage("WinTask Demonstration Pages")
    ClickHTMLElement("A[INNERTEXT= 'Same Title Pages']")

UsePage("Page Title")
     ClickHTMLElement("A[INNERTEXT= 'here']")

'Code modified to use the Navigate function.
StartBrowser("IE", "www.wintask.com/demos")
UsePage("WinTask Demonstration Pages")
Navigate("www.wintask.com/demos/identicalpage1.htm")
      ClickHTMLElement("A[INNERTEXT= 'here']")

'Note that the second UsePage function has been removed since the Navigate statement provides its own synchronization.


See also

Error Handling Overview
Handling Unexpected Windows
Handling Object not found Error
Handling Page Timeout Error
Handling Incorrect Typing
Handling Pause Error
Logging Execution