Misbehaviour of RanorexReco Generated Code on .NET component

Class library usage, coding and language questions.
y2charlie
Posts: 5
Joined: Tue Apr 14, 2009 4:33 am

Misbehaviour of RanorexReco Generated Code on .NET component

Post by y2charlie » Tue Apr 14, 2009 4:59 am

Hi there, I am currently using Ranorex 1.5 Premium for software automation. I am facing a problem in retrieving data source bound to a ComboBox (which is obtained from a third party GUI library). After endless number of trial and error, I managed to identify the primary level road block that was troubling me.

I managed to get Ranorex to identify the ComboBox but not the ButtonDropDown element within the ComboBox. Hence, I tried to use the code generated by RanorexRecorder and it works when I execute the code on RanorexRecorder.

For simplicity I copied the generated code into my source code. Unfortunately the generated code does not identify ButtonDropDown element belongs to the ComboBox that contains it. It picked up ButtonDropDown element of another control instance contained in different form. As long as Ranorex could not identified the correct element, retrieval of data source bound to the ComboBox could not be verified.

It would be great if someone could hint me on the potential cause or solution to this problem. Thanks

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 » Wed Apr 15, 2009 7:53 am

Hi,

do you know the type of the third party library which is used in your application? Did you try to analyze the combo box and its elements with Ranorex Spy?

Also, it would be easier to analyze your situation if you could provide us with the relevant code snippet generated by Ranorex Recorder.

kind regards,

Christoph
Ranorex Support Team

y2charlie
Posts: 5
Joined: Tue Apr 14, 2009 4:33 am

Post by y2charlie » Thu Apr 16, 2009 5:52 am

Hi Christoph,

The issue has now been resolved. The problem was there are several control instances with the same name and role within an active form. I have to verify the State of each element in order to identify the correct element.

Nonetheless, I am still unable to retrieve the value in drop down table (of type Infragistics ComboDropDownControl). This is mainly due to failure in locating ComboDropDownControl instance which appears after DoDefaultAction of element but.Following is the code snippet:

Note* EditorForm is of type Ranorex.Form and has been instantiated.

//To indentify corresponding Infragistics UltraCombo instance
Control child = EditorForm.FindControlName("cmbRevision");
Element controlElement = child.Element;
Element[] button = controlElement.FindChildren(Role.ButtonDropDown,
"Open");

foreach (Element but in button)
{
if (but.State == State.Normal)
{
but.DoDefaultAction();
}
}

control = child.FindClassName("WindowsForms10.Window.8.app.0.378734a", 0);

//************
control.Focus(); //This is where the null object reference occur

controlElement = control.Element;

Element[] rows = controlElement.FindChildren(Role.Cell, elementName);

//The remaining code continues here


The code was written based on information that I obtained from RanorexSpy. It would be great if you could hint me on how to locate ComboDropDownControl. Thanks in advance.

Regards,
y2charlie

y2charlie
Posts: 5
Joined: Tue Apr 14, 2009 4:33 am

Post by y2charlie » Thu Apr 16, 2009 6:45 am

I have tried the following code and it works. But the problem is I have to move the mouse pointer manually over the ComboDropDownControl instance before accessing the element contained within. It seems like a functioning solution but not a robust one. Following code is attached after but.DoDefaultAction().


//Note: x-y value of point is obtained experimentally.

Mouse.Move(point);
Control asd = Mouse.GetControl();
Element asdElement = asd.Element;
Element[] asdCell = asdElement.FindChildren(Role.Cell, "Revision");

foreach (Element ele in asdCell)
{
Console.WriteLine("{0}", ele.Value);
}

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 » Thu Apr 16, 2009 1:38 pm

I guess that the drop down list of the drop down control is a top-level form, so please try to find that control using the Application.FindForm... methods.
Additionally, for .NET controls you should usually not use the classname to search for controls, but the ControlName (Control.FindControlName method), since most .NET controls have the same classname.

In Ranorex 2.0 things would be much easier as you would simply spy the drop down and then use the generated RxPath or repository to uniquely identify the element.

Regards,
Alex
Ranorex Support Team

y2charlie
Posts: 5
Joined: Tue Apr 14, 2009 4:33 am

Post by y2charlie » Thu Apr 23, 2009 3:48 am

Hi Alex,

Thanks for the suggestion. I tried it before but it does not work. This is because the user control was created at design time and the Name property is not defined. Hence, finding a form with empty Name and Text property will most likely ended up in finding other form which also has empty definition for Name and Text. Nonetheless, the mouse pinter approach seems to be working quite well as long as there is no manual intervention during the system test.

y2charlie
Posts: 5
Joined: Tue Apr 14, 2009 4:33 am

Post by y2charlie » Thu Apr 23, 2009 10:30 am

correction:
"... the user control was created at RUN time and the Name property is not defined."