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.
To test this solution, complete the following steps:
- Download and run the attached solution in Robotic Automation Studio.
- Go to the Bing search page and then enter text into the Search field.
- Click .
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:
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.
Published December 6, 2016 — Updated June 15, 2018