Best Practices for Managing Screen Element Recognition
Automation Studio allows you to enable and disable recognition of a screen element.
The recommended best practice is to enable recognition of each screen element for only as long as it is needed, and to disable recognition when the screen element is not needed.
Why Disable Recognition of a Screen Element?
Reasons for disabling recognition of a screen element when not in use include:
-
To reduce load on system resources.
-
To prevent a situation in which two solutions monitor the same screen element as this may cause unexpected behavior.
This situation can occur in the case in which a project was built by importing a second project (as described in Recommended Solution Architecture), and both projects reference the same screen element.
How to Disable and Enable Recognition of Screen Elements
Below are recommendations on how to disable and enable recognition of a screen element. These recommendations are demonstrated in the example below the table.
REquirement |
Recommended Implementation |
---|---|
Disable recognition of screen elements when the solution is loaded initially |
Create an Event Handler as follows:
|
Enable recognition of selected screen elements when needed |
When a workflow that interacts with a screen element is started, recognition of that screen element must be enabled. The recommended best practice is to use an event handler to enable recognition of that screen element, as follows:
Alternatively, you can enable recognition of the screen element within a step of the workflow itself. |
Disable recognition of screen elements after use |
When a workflow that interacts with a screen element ends, recognition of that screen element should be disabled. The recommended best practice is to use an event handler to disable recognition of that screen element, as follows:
Alternatively, you can disable recognition of the screen element within a step at the end of the workflow itself. |
Example
An automation solution includes a single workflow in which a simple search is performed in Google using Internet Explorer. This workflow is included in a small feature project that will be imported into a larger central project. The feature project is called google_search.
The workflow is shown below:
This feature project also includes two screen elements: one for the text entry field at www.google.com and another for the Google Search button. Note that both screen elements are located below the INTERNET EXPLORER_SERVER - screen element in the hierarchy.
Although both Google screen elements are also located under the iexplore process, it is not possible to disable and then re-enable recognition of a process. We will therefore enable and disable recognition of the INTERNET EXPLORER_SERVER - element instead.
Step 1: Disable recognition of screen elements when solution is loaded
We will use an event handler to disable recognition of both screen elements when the solution is loaded. Since the screen elements have a common ancestor in the hierarchy, it is sufficient to disable recognition of that ancestor, namely, the INTERNET EXPLORER_SERVER - screen element.
Note that the ID of the INTERNET EXPLORER_SERVER - screen element is se23.
The event handler is shown below. It is triggered by the Solution Loaded event and disables recognition of the INTERNET EXPLORER_SERVER - screen element and all its descendents.
Step 2: Enable the screen elements when needed
Recognition of the screen elements must be enabled when the workflow starts.
To do so, we will add another step at the beginning of the workflow. This step uses the enable recognition function to enable recognition of the INTERNET EXPLORER_SERVER - screen element and its descendants.
It is sufficient to enable recognition of the INTERNET EXPLORER_SERVER - screen element which is a common ancestor of both screen elements used by the workflow. (Note that this will work only because we initially disabled recognition of the two screen elements by disabling recognition of the INTERNET EXPLORER_SERVER - screen element - if we disabled recognition of the two screen elements individually we would have to enable their recognition individually too.)
Step 3: Disable the screen elements after use
After the workflow has ended, there is no reason to continue to recognize its screen elements so their recognition should be disabled.
To do so, we will add another step at the end of the workflow. This step uses the disable recognition function to disable recognition of the INTERNET EXPLORER_SERVER - screen element and its descendants.
Step 4: Test the feature project
To test the event handlers created:
-
Temporarily add a breakpoint to the second step of the workflow. This lets us view the status of the screen elements after the workflow starts and before it ends.
-
Click Start Project.
Note that the two screen elements are not recognized although they are currently present in the Internet Explorer window.
-
Click Run Workflow.
The workflow starts and is paused at the breakpoint.
Note that the two screen elements are now recognized.
-
Click Continue to allow the workflow to run to completion.
The workflow ends.
Note that the two screen elements are now no longer recognized.