如何在White Framework中访问主窗口内的子窗口

时间:2016-05-25 07:18:51

标签: c# windows ui-automation white

我正在使用White框架在基于Windows桌面的应用程序中进行UI自动化。我无法找到访问子窗口的方法。 UIAVerify将窗口的属性描述为:

以下是参考代码:

public class Program
{
    Application app = Application.Launch("Path to my application");

    public Program()
    {
        //Getting the main window
        Window MainWindow = app.GetWindow("MainForm", InitializeOption.NoCache);
        MainWindow.WaitWhileBusy();
        **//Here I wanna get the child window so that I can access controls on that window. Below is the code for getting child windows controls** 
        //Getting to the Firm box
        TextBox firm = Childwindow.Get<TextBox>(SearchCriteria.ByAutomationId("1313948"));
        //setting value for firm
        firm.SetValue("FIRM2");
        //getting StaffID text box
        TextBox StaffID = Childwindow.Get<TextBox>(SearchCriteria.ByAutomationId("723272"));
        StaffID.SetValue("Staff");

        Button Ok = Childwindow.Get <Button>(SearchCriteria.ByAutomationId("_okB[enter image description here][1]utton"));
        Ok.Click();
    }

1 个答案:

答案 0 :(得分:0)

使用TreeScope.Children访问桌面的直接子元素:

AutomationElement rootElement = AutomationElement.RootElement;
    var winCollection = rootElement.FindAll(TreeScope.Children, Condition.TrueCondition);

    foreach (AutomationElement element in winCollection)
        Console.WriteLine(element.Current.Name);