DoDefaultAction and Modal Dialog

Class library usage, coding and language questions.
ChrisC
Posts: 7
Joined: Tue Oct 02, 2007 4:36 pm

DoDefaultAction and Modal Dialog

Post by ChrisC » Fri Oct 12, 2007 6:30 pm

I'm trying to automate a modal dialog that opens a file. I've tried doing this using the following code:

Code: Select all

        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

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Post by Support Team » Mon Oct 15, 2007 1:58 pm

... if I replace item.DoDefaultAction(); with Application.SendKeys("^o");, everything works as expected.

Is this the expected behavior for DoDefaultAction()?
No, DoDefaultAction() should work.
Unfortunately some user controls does not support all accessibility functions.

You have to find a workaround (e.g. with SendKeys) for such an issue.

Jenö
Ranorex Support Team