| View previous topic :: View next topic |
| Author |
Message |
shobhana
Joined: 05 Nov 2007 Posts: 3
|
Posted: Mon Nov 05, 2007 10:43 am Post subject: 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. |
|
| Back to top |
|
 |
Support Team Site Admin
Joined: 07 Jul 2006 Posts: 257
|
Posted: Mon Nov 05, 2007 12:35 pm Post subject: |
|
You can use the Ranorex Spy to identify controls and elements present in the form which are accessible by Ranorex.
Michael
Ranorex Support Team |
|
| Back to top |
|
 |
shobhana
Joined: 05 Nov 2007 Posts: 3
|
Posted: Mon Nov 05, 2007 12:44 pm Post subject: |
|
| 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. |
|
| Back to top |
|
 |
Support Team Site Admin
Joined: 07 Jul 2006 Posts: 257
|
Posted: Mon Nov 05, 2007 2:09 pm Post subject: |
|
To find all controls in a form use following C++ code
Code: click into code to enlarge
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: click into code to enlarge
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 |
|
| Back to top |
|
 |
shobhana
Joined: 05 Nov 2007 Posts: 3
|
Posted: Mon Nov 05, 2007 3:33 pm Post subject: |
|
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. |
|
| Back to top |
|
 |
Support Team Site Admin
Joined: 07 Jul 2006 Posts: 257
|
Posted: Mon Nov 05, 2007 4:35 pm Post subject: |
|
If you have several controls all having the same ClassName, that could be a problem. I can only assume that the line
Code: click into code to enlarge
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: click into code to enlarge
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 |
|
| Back to top |
|
 |
|