Unable to cast object of type 'Ranorex.Control' to ComboBox

Bug reports.
issamq
Posts: 4
Joined: Thu Apr 19, 2007 1:07 am

Unable to cast object of type 'Ranorex.Control' to ComboBox

Post by issamq » Thu Apr 19, 2007 1:11 am

I am getting this message when I try to cast ComboBox to the Control type.

Unable to cast object of type 'Ranorex.Control' to type 'Ranorex.ComboBox'.

Code: Select all

Control curComboBox = form.FindControlName(curControl.Name);
ComboBox curCmbBox = (ComboBox)curComboBox;

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

Post by webops » Thu Apr 19, 2007 10:45 pm

I tried this in V1.1.0 and it worked.
Which Ranorex and .NET Framework version do you use?

I would suggest the following function:

ComboBox comboBox = form.FindComboBox(curControl.Name);

Jenö
Ranorex Team

issamq
Posts: 4
Joined: Thu Apr 19, 2007 1:07 am

Post by issamq » Thu Apr 19, 2007 10:50 pm

I have already what you suggested and I got back null.

I am using the latest version of your tool: v1.1.0 along with .Net 1.1 and DevExpress controls.

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

Post by webops » Sun Apr 22, 2007 3:00 pm

You can't use the Ranorex.ComboBox class for DevExpress ComboBox.
I made some tests with the "XtraGrid Features Demo" of the DevExpress demo application. You can automate the DevExpress controls with the Element functionality.

The following code automates a DevExpress ComboBox(from the TableLayout page):

Code: Select all

Control newItemCombobox = form.FindControlName("icbNewItemRow");
if (newItemCombobox == null)
{ 
    Console.WriteLine("Cannot find icbNewItemRow");
    return 1;
}
Mouse.ClickControl(newItemCombobox);

Element listItem = newItemCombobox.Element.FindChild(Role.ListItem, "Top");
if (listItem == null)
{
    Console.WriteLine("Cannot find listItem");
    return 1;
}
Mouse.ClickElement(listItem);
Gabor
Ranorex Team

issamq
Posts: 4
Joined: Thu Apr 19, 2007 1:07 am

Post by issamq » Mon Apr 23, 2007 8:03 pm

That still did not work. Currently my work around is to use the sendKey to set the value of the combo box. The workaround you outlined which is using the Element is not finding the Listitem object. I looped through the Elements contained in the control, and none of them is a listitem.

Can I assume that your product does not support DevExpress controls?

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

Post by webops » Mon Apr 23, 2007 8:27 pm

I think the ListItems will be generated after a drop down operation.
You should wait a little bit after clicking on the combobox.

Try the following modified code:

Code: Select all

Control newItemCombobox = form.FindControlName("icbNewItemRow");
if (newItemCombobox == null)
{
    Console.WriteLine("Cannot find icbNewItemRow");
    return 1;
}
Mouse.ClickControl(newItemCombobox);

Application.Sleep(200);

Element listItem = newItemCombobox.Element.FindChild(Role.ListItem, "Top");
if (listItem == null)
{
    Console.WriteLine("Cannot find listItem");
    return 1;
}
Mouse.ClickElement(listItem);
Which DevExpress version do you use? I made the tests with the v7.1.
Can I assume that your product does not support DevExpress controls?
Ranorex's Element approach works with almost every custom controls(e.g. DevExpress).

If not please send us a simple application.

Gabor
Ranorex Team

issamq
Posts: 4
Joined: Thu Apr 19, 2007 1:07 am

Post by issamq » Wed Apr 25, 2007 1:08 am

And to email address to email the sample app to?

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

Post by webops » Wed Apr 25, 2007 7:50 am

Please send the sample app to: gherget(at) ranorex.com

Gabor
Ranorex Team