Dynamic identification of component types

Class library usage, coding and language questions.
Posts: 11
Joined: Sat Oct 22, 2011 12:35 am

Dynamic identification of component types

Post by jtruppia » Sat Oct 29, 2011 12:14 am

I have the following problem.
I've got a dictionary, where the keys corresponds to labels in my UI, and the values correspond to the value I must set in each control associated with that label.
The problem is that I don't know at compile time what type will the component have (it can be a textbox, combo, list, etc)
Each component shares the parent with the label, so that's the way I'm locating it.
But after that, I want to be able to create adapters (or elements) for each component, and be able, at runtime, to determine the type and using that, change the value in the appropriate way.
Is there any method that given an adapter or element can determine its type, or its capabilities??

Posts: 17
Joined: Fri Sep 02, 2011 2:56 pm

Re: Dynamic identification of component types

Post by Patrik » Thu Nov 03, 2011 5:34 pm

Hey - i'm not sure if this is what you need, but with this method you get the correct adapter for the component if you have its RxPath:

Code: Select all

public Adapter findObject(string path, int timeout) {
    Element element = Host.Local.FindSingle(path, timeout);
    RxPath rxPath= new RxPath(path);
    string capabilityName= rxPath.GetCapabilityForTailNodeTest().Name;
    System.Type adapterType = Ranorex.Core.ElementEngine.Instance.AdapterTypes[capabilityName];
    return Adapter.Create(adapterType, element);