Page 1 of 1

Identifying all the controls & elements present in a for

Posted: Mon Nov 05, 2007 9:43 am
by shobhana
Given a form I want to know whether all the controls and elements present in it are identified by Ranorex.

Posted: Mon Nov 05, 2007 11:35 am
by Support Team
You can use the Ranorex Spy to identify controls and elements present in the form which are accessible by Ranorex.

Michael
Ranorex Support Team

Posted: Mon Nov 05, 2007 11:44 am
by shobhana
I knew that we use Ranorexspy to find out the controls and elements details.But here my requirement is I have only the Form with me and I need to write a program which lists me all the controls and elements present in the form and I have to click on them and make sure it is able to identify.Everything I need to get it from the Ranorex functions,I wont use the ranorexspy at all.

Posted: Mon Nov 05, 2007 1:09 pm
by Support Team
To find all controls in a form use following C++ code

Code: Select all

HWND currentChild = RxFormGetFirstChild(form);
while (currentChild != NULL)
{
	// do something like: RxMouseClickControl(currentChild);
	currentChild = RxFormGetNextChild(form, currentChild);
}
or the Form.Controls property in C#.

To find all the elements in a form you have to write a recursive method that walks the element tree of the form:

Code: Select all

void DoForAllElements(ElementStruct* currentElement)
{
	// do something like: RxMouseClickElement(currentElement);
	for (int i = 0;  i < RxElementGetChildCount(currentElement); i++)
	{
		ElementStruct childElement;
		RxElementGetChild(currentElement, i, &childElement);
		DoForAllElements(&childElement);
	}
}

int main()
{
	HWND form = ...; // search for specific form
	ElementStruct formElement;
	RxControlGetElement(form, &formElement);
	DoForAllElements(&formElement);
}
Alex
Ranorex Support Team

Posted: Mon Nov 05, 2007 2:33 pm
by shobhana
I am doing the C# coding,this is what I am doing in my code....

foreach (Control control in BABMgrForm.Controls)
{
Console.WriteLine("ClassName= " + control.ClassName);
Control ctrl = waitForFindClassName(BABMgrForm, control.ClassName);
Element[] tabelements = ctrl.Element.FindChildren(Role.PageTab);
foreach (Element item in tabelements)
{
Console.WriteLine("Item Name", item.Name);
LogMessage(item.Name);
}
Element[] outlineelements = ctrl.Element.FindChildren(Role.Outline);
foreach (Element outlineitem in outlineelements)
{
Console.WriteLine("Item Name", outlineitem.Name); LogMessage(outlineitem.Name);
}
}

But I am not able to find any element,neither all the controls are getting displayed.Am I doing anything wrong here.

Posted: Mon Nov 05, 2007 3:35 pm
by Support Team
If you have several controls all having the same ClassName, that could be a problem. I can only assume that the line

Code: Select all

Control ctrl = waitForFindClassName(BABMgrForm, control.ClassName);
internally uses the FindClassName method. If so, this will always get you the first instance of all controls matching the specified ClassName.

So the first thing to do is replacing the above line by

Code: Select all

ctrl = control;
Your code should then get you all the elements in all controls of BABMgrForm that have a Role of 'PageTab' or 'Outline'.

If you want all the elements of a control, use the recursive method described in my former post.

Alex
Ranorex Support Team