Debug & automate any modal or modeless dialog with SWEA


Understanding how to get at the controls in a modal dialog box when using SWEA is something I never had to worry much about in the past; the SWEA example code took care of all of those that I had previously encountered. Recently I needed to automate a “Choose file’ dialog, and since there was no example, I had to buckle down to figure out how to get at the controls in that dialog. To understand the controls of this particular modal dialog, and also wanting to make sure I could handle all others I encountered in the future, I wrote some code that would dump all relevant things available in SWEA’s DialogControl class when the DialogActivatedEventHandler was fired. By doing this, when a dialog was presented, I was able to scrape all the control information out of the modal dialog. The following code in my explorerManager_DialogActivated method did the scraping and dumping:


if (this.Debug == true)
{
    Console.WriteLine
        (“–Modal dialog info——————–“);
    Console.WriteLine
        (“Modal Dialog Title: “ + dialogScene.Title);
    Console.WriteLine
        (“Modal Dialog ClassName: “ + dialogScene.ClassName);
    Console.WriteLine
        (“Modal Dialog DialogHWND: “ + dialogScene.DialogHWND);
    Console.WriteLine (“Modal Dialog XML: “ + dialogScene.Xml.ToString());
    Console.WriteLine
        (“—————-Controls in Modal dialog—————–“);
    foreach (DialogControl dlgCtrl in dialogScene.Controls)
    {
        Console.WriteLine(“Control name: ‘”
            + dlgCtrl.Name + “‘ is a type of: “ + dlgCtrl.GetType().ToString());
    }
    Console.WriteLine(“—————————-“);
}


With my new addition as noted above, when the DialogActivatedEventHandler was fired the explorerManager_DialogActivated method was invoked which resulted in the following informational console dump about my modal dialog:

—Modal dialog info——————–
Modal Dialog Title: Choose file
Modal Dialog ClassName: #32770
Modal Dialog DialogHWND: 5047980
Modal Dialog XML: <Dialog HWND=”5047980″ Title=”Choose file” Class=”#32770″><Window HWND=”7014084″ Title=”Look &amp;in:” Class=”Static”></Window><Window HWND=”5441378″ Title=”SMSIMG (C:)” Class=”ComboBox”></Window><Window HWND=”5900158″ Title=”” Class=”Static”></Window><Window HWND=”5572502″ Title=”” Class=”ToolbarWindow32″></Window><Window HWND=”8914906″ Title=”” Class=”ToolbarWindow32″></Window><Window HWND=”2623410″ Title=”” Class=”ListBox”></Window><Window HWND=”9963366″ Title=”” Class=”SHELLDLL_DefView”></Window><Window HWND=”7735164″ Title=”FolderView” Class=”SysListView32″></Window><Window HWND=”6293452″ Title=”File &amp;name:” Class=”Static”></Window><Window HWND=”6620914″ Title=”” Class=”ComboBoxEx32″></Window><Window HWND=”7735112″ Title=”” Class=”ComboBox”></Window><Window HWND=”4196138″ Title=”” Class=”Edit”></Window><Window HWND=”58918660″ Title=”Files of &amp;type:” Class=”Static”></Window><Window HWND=”14419712″ Title=”All Files (*.*)” Class=”ComboBox”></Window><Window HWND=”3016576″ Title=”Open as &amp;read-only” Class=”Button”></Window><Window HWND=”7276400″ Title=”&amp;Open” Class=”Button”></Window><Window HWND=”10946288″ Title=”Cancel” Class=”Button”></Window><Window HWND=”6227962″ Title=”&amp;Help” Class=”Button”></Window><Window HWND=”7079840″ Title=”” Class=”ScrollBar”></Window></Dialog>
—————-Controls in Modal dialog—————–
Control name: ‘Static_0’ is a type of: SWExplorerAutomation.Client.DialogControls.DialogStatic
Control name: ‘Static_1’ is a type of: SWExplorerAutomation.Client.DialogControls.DialogStatic
Control name: ‘Static_2’ is a type of: SWExplorerAutomation.Client.DialogControls.DialogStatic
Control name: ‘Edit_0’ is a type of: SWExplorerAutomation.Client.DialogControls.DialogEdit
Control name: ‘Static_3’ is a type of: SWExplorerAutomation.Client.DialogControls.DialogStatic
Control name: ‘Open as read-only’ is a type of: SWExplorerAutomation.Client.DialogControls.DialogButton
Control name: ‘Open’ is a type of: SWExplorerAutomation.Client.DialogControls.DialogButton
Control name: ‘Cancel’ is a type of: SWExplorerAutomation.Client.DialogControls.DialogButton
Control name: ‘Help’ is a type of: SWExplorerAutomation.Client.DialogControls.DialogButton
———————————————————


After extracting the control information I needed for my test from the console dump, in the same explorerManager_DialogActivated method I created a condition for the “Choose File” modal dialog that inserted a file location/name and then clicked the “Open” button:

//Manage the ‘Choose file’ dialog box
if (dialogScene.Title == “Choose file”)
{
if (dialogScene.ControlExists(“Edit_0”))
{
dialogScene.DialogEdit(“Edit_0”).Text =
            this.ChooseFileLocation;
}
if (dialogScene.ControlExists(“Open”))
{
dialogScene.DialogButton(“Open”).Click();
}
Check the automation of another modal dialog box off my list! …and even better, I’m now setup to dump information about any others that might cross my path.

Leave a Reply

Your email address will not be published. Required fields are marked *