如何使用TestStack.White单击菜单下的按钮

时间:2017-03-27 05:15:05

标签: c# ui-automation

enter image description here我尝试使用white点击新项目按钮,我尝试使用下面的代码,但它不起作用,任何人都可以帮助我吗?

 public void Notepad()
        {
            Application app = Application.Launch("C:\\Program Files (x86)\\SourceMonitor\\SourceMonitor.exe");
            Window window = app.GetWindow("SourceMonitor", InitializeOption.NoCache);

            Button button = window.Get<Button>("File");
            button.Click();


            app.Kill();

        }

1 个答案:

答案 0 :(得分:1)

我已经想出了怎么做,下面是正确的代码:

 public void Notepad()
        {
            // Arrange
            Application app = Application.Launch("C:\\Program Files (x86)\\SourceMonitor\\SourceMonitor.exe");
            Window window = app.GetWindow("SourceMonitor", InitializeOption.NoCache);

            // Act

            MenuBar menuBar = window.MenuBar;
            menuBar.MenuItem("File","New Project").Click(); ; //can use any other search criteria as well.
}