Class library usage, coding and language questions.
Posts: 3
Joined: Thu Jul 12, 2007 4:45 pm


Post by dave0989 » Wed Jul 18, 2007 9:53 pm

Well I have accomplished a lot so far with automating the GUI testing at my work... I'm happy with Ranorex and I plan on writing a proposal for a license..

Anyways I have a question regarding pushbutton. So far I have tried to write the code myself with no success then I tried to use RanorexRecorder to record the process of selecting okay from a child dialog box that apprears.

// Find child element by Role=PushButton Name=OK ClassName=Button
element = formElement.FindChild(Role.PushButton, "OK", "Button");
Mouse.ClickControl(control, MouseButtonType.LeftButton, new Point(47, 12), 1, 953);

What happens is the cursur goes right past the dialog box and I get an error message.

It throws a commandfailed exception.

Site Admin
Site Admin
Posts: 350
Joined: Wed Jul 05, 2006 7:44 pm

Post by admin » Wed Jul 18, 2007 11:02 pm

Did you use the dialog element in the FindChild(Role.PushButton) function?

The following code works with the sample VS2005Application.exe:
It opens the FileOpen dialog, finds the dialog, sets the file name and clicks the Open PushButton.

Code: Select all

ret = menuStrip.SelectItemText("Submenu3", "FileOpen");

Form openFileDialog = Application.FindFormTitle("Open",SearchMatchMode.MatchExact,true,1000);
if (openFileDialog == null)
    Console.WriteLine("ERROR: OpenFileDialog not found ");
    return 1;

Element fileEditControl = openFileDialog.Element.FindChild(Role.Text,"File name:"); 
if( fileEditControl != null)
    fileEditControl.Value = "D:\\Ranorex-1.2.0\\Bin\\RanorexSpy.exe";

Element openButton = openFileDialog.Element.FindChild(Role.PushButton,"Open","Button");
if (openButton != null )
Please try it and post a replay if it doesn't work.

Ranorex Team