Identifying all the controls & elements present in a for
Identifying all the controls & elements present in a for
Given a form I want to know whether all the controls and elements present in it are identified by Ranorex.
- Support Team
- Site Admin
- Posts: 12167
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Graz, Austria
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.
- Support Team
- Site Admin
- Posts: 12167
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Graz, Austria
To find all controls in a form use following C++ code
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:
Alex
Ranorex Support Team
Code: Select all
HWND currentChild = RxFormGetFirstChild(form);
while (currentChild != NULL)
{
// do something like: RxMouseClickControl(currentChild);
currentChild = RxFormGetNextChild(form, currentChild);
}
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);
}
Ranorex Support Team
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.
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.
- Support Team
- Site Admin
- Posts: 12167
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Graz, Austria
If you have several controls all having the same ClassName, that could be a problem. I can only assume that the line
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
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
Code: Select all
Control ctrl = waitForFindClassName(BABMgrForm, control.ClassName);
So the first thing to do is replacing the above line by
Code: Select all
ctrl = control;
If you want all the elements of a control, use the recursive method described in my former post.
Alex
Ranorex Support Team