Dialog and ModalDialog

Class library usage, coding and language questions.
lasombra
Posts: 14
Joined: Tue Mar 04, 2008 1:36 pm

Dialog and ModalDialog

Post by lasombra » Fri Mar 07, 2008 8:30 pm

I have a Ranorex test client, which opens on the application-to-test a modal dialog "Standard User" where I enter some user information like username and password. If all information are entered, I click on "OK". Well if the user exists, a dialog "Standard User" appears, where I either must to click "Yes" or "No". Here the tree which I receive of UISpy:

Code: Select all

+window "main window"
+-window "Standard User" (ModalDialog)
  +-dialog "Standard User"
    +button "Yes"
    +button "No"
Here I try to show the situation:

Code: Select all

+--------------------------------------+
|Standard User                         |
+--------------------------------------+
|                                      |
| User Name        [      ]            |
|       +===========================+  |
| Passw |Standard User              |<---- this dialog I cannot detect
|       +===========================+  |
| Confi |      [YES]      [NO]      |  |
|       +===========================+  |
|                                      |
+--------------------------------------+
My Problem is, that I couldn't get in any form the "dialog" which seems to be a child of the window "Standard User".

Code: Select all

localControl = myModalDialog.FindClassName("#32770"); //myModalDialog = Ranorex.Form
localControl = myModalDialog.FindChildText("Standard User");
localElement = myForm2.Element.FindChild(Ranorex.Role.Dialog, "Standard User");
Exists a possibility to get the dialog and press one of the buttons?

lasombra
Posts: 14
Joined: Tue Mar 04, 2008 1:36 pm

Post by lasombra » Fri Mar 07, 2008 8:52 pm

In the end I got it: First RTFM ;-) A Dialog is a Ranorex.Form thus I can search by classname on the Ranorex.Application:

Code: Select all

Ranorex.Application.FindFormClassName("#32770");

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 Mar 10, 2008 9:14 am

Dialogs are top-level windows, i.e. the do not have a parent window. So you got to search them using the Ranorex.Application class.

Glad you could do it on your own :D

Alex
Ranorex Support Team

lasombra
Posts: 14
Joined: Tue Mar 04, 2008 1:36 pm

Post by lasombra » Mon Mar 10, 2008 1:28 pm

If dialogs are top level windows, why UISpy shows me the dialog as a child? Well this is another thing... But still I have a problem with the dialog. I get the dialog by classname, and is the only dialog.

Code: Select all

foreach (Ranorex.Form topform in Ranorex.Application.Forms)
{
   if (topform.ClassName.Equals("#32770"))
   {
      Console.WriteLine("Form= " + topform.Text + ", Classname=" + topform.ClassName);
   }
}
gives me

Code: Select all

Form= Standard User, Classname=#32770
So far, so good, but the form that I found, don't contains any controls, thus the following code don't show me anything:

Code: Select all

foreach (Ranorex.Control myControl in localForm.Controls) 
{
   Console.WriteLine("Text= " + myControl.Text + ", " + myControl.ClassName);
}
On the other side, I get childrens, but the children notes are not of the expected dialog.

Code: Select all

for (int k = 0; k < localForm.Element.ChildCount; k++)
{
   Console.WriteLine("Text= " + localForm.Element.GetChild(k).Name);
}
gives me

Code: Select all

Text= System
Text=
Text= Application
Text= Google Calendar Sync 0.9.3.0
Text= Vertical
Text= Vertical
Text=
"Google Calendar Sync" is an application that is running in the system tray. Before I had childs of an Outlook reminder - the reminder came in the morning, I closed it and I closed too Outlook, but Outlook still was running as a process. After kill the process, I get the results mentioned above.

This behavior is very rare. Any suggestions?

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 Mar 10, 2008 3:10 pm

lasombra wrote:If dialogs are top level windows, why UISpy shows me the dialog as a child?
Sorry, I was a little imprecise: dialog windows do have parent windows, but they are not the child of that window. So you got to search them as if they were top-level windows.

It seems that you are sometimes finding the wrong dialog. There are many dialogs with classname "#32770" open all the time, even if they are invisible. It's much safer to search for the window caption "Standard User" and the classname.

Code: Select all

Form dialog = Ranorex.Application.FindForm("Standard User", Ranorex.SearchMatchMode.MatchExact, "#32770");
Regards,
Alex
Ranorex Support Team

lasombra
Posts: 14
Joined: Tue Mar 04, 2008 1:36 pm

Post by lasombra » Mon Mar 10, 2008 3:57 pm

Thanks Alex, this is what I am looking for, unfortunately Ranorex doesn't provide a FindForm(), although mentioned in the documentation.

Assembly: RanorexNet (Module: RanorexNet) Version: 1.2.0.0
DevEnv: Visual C# Express 2008

The ObjectBorwser of the Visual Express only provides me only the methods FindFormTitle() and FindFormClassName().

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 Mar 10, 2008 4:50 pm

lasombra wrote:unfortunately Ranorex doesn't provide a FindForm(), although mentioned in the documentation.
You need to reference the RanorexNet.dll from the bin\Net2.0-Pro directory! This method is only supported in the Pro version of Ranorex.

Alex
Ranorex Support Team