window.ModalWindow(criteria) doesn't work

Nov 18, 2012 at 10:59 AM

Look at the simple code base on notepad.exe.

Scenario:

1. open notepad

2. type something

3. send Ctrl + S

4. try to find modal Save As dialog using Window.ModalWindow(criteria)

===>

Cannot find, null returns..

 

var app = Process.GetProcessesByName("notepad").Length == 0
	  ? Application.Launch("notepad")
	  : Application.Attach("notepad");
var mainWindow = app.GetWindow(SearchCriteria.ByNativeProperty(AutomationElement.ClassNameProperty, "Notepad"), InitializeOption.NoCache);
mainWindow.Focus(DisplayState.Restored);
SendKeys.SendWait("^(s)");
mainWindow.WaitWhileBusy();

// works in such ways
var modals = mainWindow.ModalWindows().Where(w => w.AutomationElement.GetCurrentPropertyValue(AutomationElement.NameProperty).Equals("Save As")).ToArray()[0];
var fromApp = app.GetWindows().Find(w => w.Title.Equals("Save As"));

// doesn't work for all the tries below

// null
var try1 = mainWindow.ModalWindow("Save As");
// null
var try2 = mainWindow.ModalWindow(SearchCriteria.ByNativeProperty(AutomationElement.ClassNameProperty, "#32770"));
// Exception is thrown
//var try3 = app.GetWindow("Save As");

 

Any ideas why Window.ModalWindow(criteria) doesn't work? Is it a bug, or something wrong in the code above?