Table of Contents

Article

Example: Handling cancelable events in .NET

Some events, such as button clicking, are passed to the automation code before the application gets the event. These events are named with the -ing suffix, such as Clicking and RightClicking. You handle all of these events and then, optionally, pass them to the application. If you choose not to pass an event to the application, the event is cancelled.

Cancelable events receive the CancelEventArgs argument, which has the Cancel property. To prevent an event from being passed to the application, set the Cancel property to True and then handle the event as needed in your automation.

In the attached solution, the homePageBox text field object is associated with the Search field on the Bing search page. The searchResultsBox text field object is associated with the Search field on the Bing search results page. If the text in the Bing Search field matches the text in the equals block, the system cancels the search.

Handling cancellable events example

To test this solution, complete the following steps:

  1. Download and run the attached solution in Robotic Automation Studio.
  2. Go to the Bing search page and then enter text into the Search field.
  3. Click Search.
This exercise works both for the Bing search home page and for the search results page. There are many ways to do this, but this example uses a separate control for each page, as shown in the preceding example.

The Document Title match rule for the home page matches any webpage with “Bing” in the title. To uniquely identify the Bing search page, use the Document URL match rule. The following example shows the properties for this match rule:

Match rule properties

The Path field contains a regex expression, \bsearch\b. The match rule criteria shown in this example identifies URLs that contain “search” as the correct URL for the search page.

Pega Robotic Automation Studio versionBuilt using versionDownload
8.08.0.1084Cancel Event Example 8.0

Published December 6, 2016 — Updated June 15, 2018


100% found this useful

Have a question? Get answers now.

Visit the Pega Support Community to ask questions, engage in discussions, and help others.