What is the API for Windows UI Controls

Ask general questions here.
md.eshaq
Posts: 4
Joined: Fri Feb 06, 2015 7:25 am

What is the API for Windows UI Controls

Post by md.eshaq » Fri Feb 06, 2015 7:41 am

Hi,

What is the API for Windows UI Controls as we have WebElement for web and AndroidElement for Android.
Do we have something as WindowsElement?

Because I want to write a similar function as below to find the Windows UI Controls
public static WebElement FindUIObject(string UIObjectName)
{		
int ChildObjectsCount = 0;			
	IList<Ranorex.Core.Repository.RepoItemInfo> ListOfParentObject = null;
	IEnumerator<Ranorex.Core.Repository.RepoItemInfo> ListOfChildObjects = null;
	IList<Ranorex.Core.Repository.RepoItemInfo> ListOfObjects = null;
	UIObjectName = "ObjectRepository." + UIObjectName;	

	IEnumerator<Ranorex.Core.Repository.RepoItemInfo> ListOfAllObjects = OR.SelfInfo.Children.GetEnumerator();		while(ListOfAllObjects.MoveNext())
		{
			if(UIObjectName.Contains(ListOfAllObjects.Current.ParentFolder.ToString()))
			{
				ListOfParentObject = ListOfAllObjects.Current.Children;
				ListOfChildObjects = ListOfParentObject.GetEnumerator();
				break;
			}
		}
		
	WebElement MyWebElement = null;
		
	MyWebElement = FindObjectInList(ListOfParentObject,UIObjectName);
	if(MyWebElement == null)
	{
		while(ListOfChildObjects.MoveNext())
		{
			ListOfObjects = ListOfChildObjects.Current.Children;
			ChildObjectsCount = ListOfObjects.Count;
			if(ChildObjectsCount > 0)
			{					
				MyWebElement = FindObjectInList(ListOfObjects,UIObjectName);
				if(MyWebElement != null)
				{
					return MyWebElement;
				}
				else if (MyWebElement == null)
				{
					GlobalValue.ErrorMessage = "Object not found in the object repository";
				}
			}
			else
			{
				break;
			}
		}
	}		
	return MyWebElement;
}
Last edited by Support Team on Fri Mar 20, 2015 10:20 am, edited 1 time in total.
Reason: Support Team: Edited for better readability

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: What is the API for Windows UI Controls

Post by krstcs » Fri Feb 06, 2015 4:00 pm

http://www.ranorex.com/Documentation/Ranorex/

You could probably use Element or Adapter, depending on what you are doing.

Also, please enclose code areas in the
tags.
Shortcuts usually aren't...

md.eshaq
Posts: 4
Joined: Fri Feb 06, 2015 7:25 am

Re: What is the API for Windows UI Controls

Post by md.eshaq » Thu Mar 19, 2015 7:22 am

Hi,

I have used object type as "Adopter" as I could not do find "Click()" function for type "Element" as suggested by you.


I have written the below code to find an Widows Desktop object in repository. I am passing a string as "ObjectRepository.UntitledPaint.Home.Line" to search the Object in Repository.

I have the below code which is working to search an Object of type "AndroidElement" and "WebElement" but, when I use the same code with type "Adopter" it is gives error (at the line marked in red and bold) that "Cannot implicitly convert type 'string' to 'Ranorex.Adapter' ".

Please let me know how I can find the object in repository by passing a string "ObjectRepository.UntitledPaint.Home.Line". As I said I have successfully achieved this for "AndroidElement" and "WebElement" and now I want the same for Windows Desktop Element.

The code is as below:
public static Adapter FindDesktopElement(string UIObjectName)
		{
			int ChildObjectsCount = 0;			
			IList<Ranorex.Core.Repository.RepoItemInfo> ListOfParentObject = null;
			IEnumerator<Ranorex.Core.Repository.RepoItemInfo> ListOfChildObjects = null;
			IList<Ranorex.Core.Repository.RepoItemInfo> ListOfObjects = null;
			UIObjectName = "ObjectRepository." + UIObjectName;
						
			//To Find the application
			IEnumerator<Ranorex.Core.Repository.RepoItemInfo> ListOfAllObjects = OR.SelfInfo.Children.GetEnumerator();			
			while(ListOfAllObjects.MoveNext())
			{
				if(UIObjectName.Contains(ListOfAllObjects.Current.ParentFolder.ToString()))
				{
					ListOfParentObject = ListOfAllObjects.Current.Children;
					ListOfChildObjects = ListOfParentObject.GetEnumerator();
					break;
				}
			}
			
			Adapter MyDesktopElement = null;
			
			MyDesktopElement = FindDesktopElementInList(ListOfParentObject,UIObjectName);
			if(MyDesktopElement == null)
			{
				while(ListOfChildObjects.MoveNext())
				{
					ListOfObjects = ListOfChildObjects.Current.Children;
					ChildObjectsCount = ListOfObjects.Count;
					if(ChildObjectsCount > 0)
					{					
						MyDesktopElement = FindDesktopElementInList(ListOfObjects,UIObjectName);
						if(MyDesktopElement != null)
						{
							return MyDesktopElement;
						}
						else if (MyDesktopElement == null)
						{
							GlobalValue.ErrorMessage = "Object not found in the object repository";
							GeneralTasks.TakeSnapShot();
						}
					}
					else
					{
						break;
					}
				}
			}
			return MyDesktopElement;
		}
		public static Adapter FindDesktopElementInList(IList<Ranorex.Core.Repository.RepoItemInfo> ListOfParentObject,string UIObjectName)
		{
			Adapter MyDesktopElement = null; 
			
			string PathOfObject;
			if(ListOfParentObject != null)
			{
				foreach (var ParentObject in ListOfParentObject)
				{
					if (ParentObject.ToString().Trim()  == UIObjectName.Trim())
					{
						PathOfObject = ParentObject.AbsolutePath.ToString();
MyDesktopElement = PathOfObject;
break;						
					}                    
				}
                if (MyDesktopElement == null)
                {
                    foreach (var ParentObject in ListOfParentObject)
                    {
                        if (ParentObject.Children.Count > 0)//.ToString().Trim() == UIObjectName.Trim())
                        {                            
                           MyDesktopElement =  FindDesktopElementInList(ParentObject.Children, UIObjectName);
                        }
                    }
                }
			}
			return MyDesktopElement;
		}
But
Last edited by Support Team on Fri Mar 20, 2015 10:27 am, edited 2 times in total.
Reason: Support Team: Edited for better readability