The custom property grid inherits from .net framework PropertyGrid class and is embedded in a tab control.
It works to find the control with:
Ranorex.TabControl tabControl = Common.ChangeTabPage("Sources");
Control propertyGrid = tabControl.FindChildText("PropertyGrid");
Inside the grid there is a toolstrip control with 4 buttons. I cant find the buttons. I tried different ways, but none of them worked, e.g.
// returns a null reference
Control toolbar = propertyGrid.FindControlName("ToolBar");
Control btnAdd = toolbar.FindControlName("Add");
I am using Ranorex v1.5
Thanks a lot!
Cant find toolbar buttons within a custom PropertyGrid
-
- Posts: 2
- Joined: Mon Oct 27, 2008 10:48 am
- Support Team
- Site Admin
- Posts: 12167
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Graz, Austria
Have you inspected the property grid with RanorexSpy?
If your property grid works like the default one, then the toolbar does not have a control name and the buttons are no controls, but elements. In that case you need to search for the toolbar by classname or control text (Control.FindChildText() method). And the buttons are usually represented by elements, so an Element.FindChild("Add") statement should work.
Regards,
Alex
Ranorex Support Team
If your property grid works like the default one, then the toolbar does not have a control name and the buttons are no controls, but elements. In that case you need to search for the toolbar by classname or control text (Control.FindChildText() method). And the buttons are usually represented by elements, so an Element.FindChild("Add") statement should work.
Regards,
Alex
Ranorex Support Team
-
- Posts: 2
- Joined: Mon Oct 27, 2008 10:48 am
Yes, I did.
I get a reference of the toolbar with the FindChildText() Method. That works so far.
toolbar.Element.FindChild("add") does not exist.
I tried to get the buttons callling FindChild(Role.Pushbutton, "Add"), without success.
With FindClassName() i am not sure what control i actually get because the grid, the toolbar and the buttons have the same class name and instance number. However, i get some control but calling FindChild with the same parameters as above also fails.
Regards,
Alfred.
I get a reference of the toolbar with the FindChildText() Method. That works so far.
toolbar.Element.FindChild("add") does not exist.
I tried to get the buttons callling FindChild(Role.Pushbutton, "Add"), without success.
With FindClassName() i am not sure what control i actually get because the grid, the toolbar and the buttons have the same class name and instance number. However, i get some control but calling FindChild with the same parameters as above also fails.
Regards,
Alfred.
- Support Team
- Site Admin
- Posts: 12167
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Graz, Austria
All .NET controls (except for special ones like ComboBox) have the same classname. So using the classname to search for a specific .NET control is not a good idea. The ControlName is a much better choice.alfred wertner wrote:With FindClassName() i am not sure what control i actually get because the grid, the toolbar and the buttons have the same class name and instance number.
From your description I assume that this is not a Ranorex bug, but some application/control that is difficult to automate. If you send us a sample of that PropertyGrid and a description of what you're trying to achieve, I will try to compile a short Ranorex example for you.
Regards,
Alex
Ranorex Support Team
Hi Alex!
Thanks for the quick help!
This runs perfectly now:
Thanks for the quick help!
This runs perfectly now:
Code: Select all
Ranorex.Element addButton = null;
Control tabControl = null;
Control tabPage = null;
Control propertyGridToolBar = null;
tabControl=TubeBuilder.FormApp.FindTabControl("tabControlBuildingBlockStructureHandler");
tabControl.SelectedText = "Sources";
tabPage = tabControl.FindChildText("Sources");
propertyGridToolBar = tabPage.FindChildText("PropertyGridToolBar");
addButton =propertyGridToolBar.Element.FindChild(Role.PushButton, "Add");[