This content has been archived and is no longer being updated. Links may not function; however, this content may be relevant to outdated versions of the product.
LinkedIn
Copied!

How do I cancel key or click events on web controls?

Some events on web controls and web pages cannot be canceled by setting the Cancel property on the event to True.

If the control is a link or a submit button which execute actions without script, such as navigating to a link or submitting the form, setting the Cancel property to True cancels these events. Events with inline event handlers such as; onclick=”submitform()” cannot be cancelled using the traditional Cancel property on the event.

Internet Explorer notifies Studio of clicks or key presses after the original event logic has already occurred. This means that setting the Cancel property to True on the event in an automation will not cancel the original event logic. It will, however, prevent the event from flowing up to parent HTML elements. To cancel events for web controls, you need to use ExecuteScript to override the logic that is associated with the events.

To cancel the Click event

  1. Interrogate the control you want to cancel the event on.
  2. Add a handler for the Created event for this control in an automation.
  3. After the Created event is fired, call the ExecuteScript method on the web page calling the following script: elementid.onclick = "";
  4. If you need to execute the original click logic at some point, use ExecuteScript to call the original script for the onclick event.

Note: You may also need to clear out the onmousedown and onmouseup events in the ExecuteScript call, if they are used by the control you are interrogating.

To cancel the KeyPress event

  1. Interrogate the control you want to cancel the event on.
  2. Add a handler for the Created event for this control in an automation.
  3. After the Created event is fired, call the ExecuteScript method on the web page calling the following script: elementid.onkeypress = "";
  4. If you need to execute the original key press logic at some point, use ExecuteScript to call the original script for the onkeypress event.

Note: You may also need to clear out the onkeyup and onkeydown events in the ExecuteScript call, if they are used by the control you are interrogating.

This example shows how to cancel the click event on an HTML button. The source HTML used in this example is:


<button type="submit" onclick="alert('onclick');" id="button1">OnClick</button>


0% found this useful

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.