I'm trying to automate a modal dialog that opens a file. I've tried doing this using the following code:
Code: click into code to enlarge
public void FileOpen_Menu(String fileName, Boolean open)
{
Element item = mainMenu.Element.FindChild(Role.MenuItem, "File Open");
if (item != null && item.State != State.Unavailable)
{
item.DoDefaultAction();
Application.Sleep(2000);
Control openDialog = Application.FindFormTitle("Open Diagram");
Element textBox = openDialog.Element.FindChild(Role.Text, "File name:");
textBox.Value = fileName;
Element btn;
if (open)
btn = openDialog.Element.FindChild(Role.PushButton, "Open", "Button");
else
btn = openDialog.Element.FindChild(Role.PushButton, "Cancel", "Button");
Mouse.ClickElement(btn);
}
}
The dialog opens and the execution hangs on DoDefaultAction(). However, if I replace item.DoDefaultAction(); with Application.SendKeys("^o");, everything works as expected.
Is this the expected behavior for DoDefaultAction()? I am using the trial version.
Thanks in advance for your help.
ChrisC |