Pre-requisites
.NET 3.5 framework
Please look at Configuration in case you want to change the default configuration.
Getting hold of a window
Application application = Application.Launch("foo.exe");
Window window = application.GetWindow("bar", InitializeOption.NoCache);
White uses the UI Automation API (UIA) to find controls on a window. UIA communicates to a displayed window via window messages. This find is performed by iterating through all the controls in a window. This can be slow for windows which have a lot of UIItems. White supports position-based caching of UIItem find results to improve performance. WithCache creates a cache of PrimaryUIItems. This cache is not meant to be used directly by automation programs.
Finding a UI Item and performing action
Button button = window.Get<Button>("save");
button.Click();
Finding a UIItem based on SearchCriteria
SearchCriteria searchCriteria = SearchCriteria.ByAutomationId("name").AndControlType(typeof(TextBox)).AndIndex(2);
TextBox textBox = (TextBox) window.Get(searchCriteria);
textBox.Text = "Anil";
Getting window
Application Windows
List<Window> windows = application.GetWindows(); //Returns a list of all main windows in belonging to an application. It doesn't return modal windows.
Window mainWindow = application.GetWindow("main"); //Returns a window with provided title.
Desktop Windows
List<Window> windows = Desktop.Instance.Windows(); //Returns a list of all main windows on the desktop. It doesn't return modal windows.
Modal windows
Window mainWindow = application.GetWindow("main");
List<Window> modalWindows = mainWindow.ModalWindows(); //list of all the modal windows belong to the window.
Window childWindow = mainWindow.ModalWindow("child"); //modal window with title "child"
childWindow.IsModal; //returns true
window.MessageBox can also be used for getting a message box window, which is special modal window.
Mdi child window
Use it to find a MDI child belonging to a window.
Window window = Desktop.Instance.Windows().Find(obj => obj.Title.Contains("Microsoft Visual Studio"));
if (window == null) return;
window.MdiChild(SearchCriteria.ByControlType(ControlType.Pane).AndByText("FooObject.cs"));