Working with Custom Controls. Help needed

Sep 13, 2010 at 9:45 PM

Hi,

I am testing an application where i have a custom control that is a container and contains text boxes and labels. the custom control has an Automation ID too. How do i access that custom control and the controls inside that. I appreciate your help.

I tried the below code but didn't work

[ControlTypeMapping(CustomUIItemType.Pane)]
public class MyUIItem : CustomUIItem
{
// Implement these two constructors. The order of parameters should be same.
public MyDateUIItem(AutomationElement automationElement, ActionListener actionListener)
: base(automationElement, actionListener)
{
}

//Empty constructor is mandatory with protected or public access modifier.
protected MyUIItem() {}


}

MyUIItem myUIItem = window.Get<MyUIItem>("dateOfBirth");

But myUIItem is always null. What is the problem here?

 

 

Sep 14, 2010 at 7:42 AM

Hi

try

in some cases

 

MyUIItem myUIItem = (MyUIItem)window.Get("dateOfBirth");

helps or:

AutomationElement element = window.GetElement(SearchCriteria.ByAutomationID("dateOfBirth"));

MyUIItem myUIItem = new MyUIItem(element, window.ActionListener);

 

does this work?

 

Throndorin

Sep 14, 2010 at 10:47 PM

Throndorin,

 

Thanks for the reply. I tried both the above solutions. The first one was throwing an exception of type conversion. The second on return a null object.  Here is what i ended up doing which worked.

 

            AutomationElement aeCustomContainer = window.GetElement(SearchCriteria.ByAutomationId("dateOfBirth"));

             //here i am just getting the first Label from the container but i can access all others too by AutomationElement.NameProperty, or AutomationIdProperty
             AutomationElement ae = aeCustomContainer.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Text));

            Label = new Label(ae, window.ActionListener);

So i am using Windows Automation framework and then converting the types back to white to work with them easily. Is this a good way to do it? or there is a better way of doing it?

Here i