user5768866
user5768866

Reputation:

How to use TestStack.White to click the button under the menu

enter image description hereI tried to use white to click the new project button, I try using the below code, but it can not work, anyone can help me?

 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();

        }

Upvotes: 1

Views: 1182

Answers (1)

user5768866
user5768866

Reputation:

I already figured out how to do it, below is the correct code:

 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.
}

Upvotes: 1

Related Questions