Dynamically create Adapter from RepoItemInfo
Posted: Thu Nov 12, 2015 12:08 am
I want to create a generalize method to set an adapter's attribute based on the RepoItemInfo.
Normally, I would do something like this:
But, how do you dynamically get the intended Adapter type at run time? I thought RepoItemInfo.GetType() would do the trick, but it doesn't.
The below thread shows me how to do it using the RxPath, but I was wondering if we can do it directly from the RepoItemInfo object.
http://www.ranorex.com/forum/dynamic-id ... t2753.html
The below code snippet is what I would like to do, but obviously it won't work:
Thanks for the help!
Normally, I would do something like this:
Code: Select all
Ranorex.Text textAdapter = itemInfo.CreateAdapter<Ranorex.Text>(true);
Ranorex.Input inputAdapter = itemInfo.CreateAdapter<Ranorex.Input>(true);
The below thread shows me how to do it using the RxPath, but I was wondering if we can do it directly from the RepoItemInfo object.
http://www.ranorex.com/forum/dynamic-id ... t2753.html
The below code snippet is what I would like to do, but obviously it won't work:
Code: Select all
public void SetAttribute(RepoItemInfo itemInfo, string attribute, string value)
{
if (itemInfo.Exist())
{
Ranorex.Adapter itemAdapter = itemInfo.CreateAdapter<itemInfo.GetType()>(true);
itemAdapter.Element.SetAttributeValue(attribute, value);
}
}