This section describes how to set an event to fire when a window opens, in order to obtain an instance of the window.
A WindowOpened event belongs to the ServiceBase class. All windows opened in the desktop which are the direct descendants of Desktop arrive to the handler of this event. If a window has been identified properly according to the Repository, the appropriate object will be created and passed as a sender to the handler.
It is possible to check whether a sender object comes from a specific type, and perform required operations.
All windows which were not identified also reach the handler, but the sender will be an instance of AutomationElement.
To access the AutomationElement instance:
1.Manually add the following reference to the project:
2.Add the following using statement to the project code:
using System.Windows.Automation; |
The AutomationElement instance has the following APIs to help identify the unknown window:
In addition, the following APIs provide quick handling of unknown windows:
•This API tries to handle a dialog box by pressing a button located on the dialog. The dialog is identified by caption and inner text.
DialogBox.TryHandleDialogBox(object sender, string caption, string innerText, string buttonName) |
•This API also tries to handle a dialog box by pressing a button located on the dialog. The dialog is identified by caption, className, and inner text.
DialogBox.TryHandleDialogBox(object sender, string className, string caption, string innerText, string buttonName) |