private void AutomateMainWindow(AutomationElement mainWindow) { // find the Paint.Net drawing Canvas var canvas = mainWindow.FindDescendentByIdPath(new[] { "appWorkspace", "workspacePanel", "DocumentView", "scrollableCanvasControl", "canvasView" }); DrawSpirographWaveOnCanvas(canvas); // the the audience appreciate the masterpiece! Delay(5000); var closeButton = mainWindow.FindDescendentByIdPath(new[] {"TitleBar", "Close"}); closeButton.GetInvokePattern().Invoke(); // give chance for the close dialog to open Delay(); var dontSaveButton = mainWindow.FindDescendentByNamePath(new[] {"Unsaved Changes", "Don't Save"}); Mouse.MoveTo(dontSaveButton.GetClickablePoint().ToDrawingPoint()); Mouse.Click(MouseButton.Left); }