Forum Discussion

neha_renukdas's avatar
neha_renukdas
Occasional Contributor
14 years ago

How to access child objects from a Parent object?

Suppose if we have a Parent object eg: A WinFormsObject("xTabProject") which has child object like Tab controls.I used Find method to find the parent object and then in that object i need to access its child object like double clicking on Tabs/right click on tabs.



I tried using the .Net properties to get the selected tab index, tab count, etc. but couldn't do. Can anyone help me on this, please?

7 Replies

  • neha_renukdas's avatar
    neha_renukdas
    Occasional Contributor
    Thanks Jay,



    I could get all the properties of tabs, but after finding the child object, apart from ClickTab(), there is no other method for working with tabs. Like I was expecting DblClickTab(), RClickTab(), etc. methods which could work same as ClickTab() and can be worked out after passing just the tab index



    But i had to find the co-ordinates and the use DblClick and RClick



    Is there any way to get the co-ordinates (X,Y) where the mouse just clicked on the application?

    so that i can use ClickTab() and the get the co-ordinates where it clicked and then can pass those co-ordinates for DblClick() and RClick()

    :)

  • Hello Neha,


    Here is the code that should work for you:




    function ClickRTab(tab_ctrl, index)



      var rect = tab_ctrl.GetTabRect(index);     

      X = rect.Left + rect.Width/2;

      Y = rect.Top + rect.Height/2;

      tab_ctrl.ClickR(X, Y); 

    }


    function DblClickTab(tab_ctrl, index)



      var rect = tab_ctrl.GetTabRect(index);     

      X = rect.Left + rect.Width/2;

      Y = rect.Top + rect.Height/2;

      tab_ctrl.DblClick(X, Y); 

    }


    function Test()

    {

      //...

      var tab = parentObj.WinFormsObject("xTabProject");

      for (var i = 0; i < tab.wTabCount; i++)

      {

        DblClickTab(tab, i);

        ClickRTab(tab, i);   

      }

    }

  • neha_renukdas's avatar
    neha_renukdas
    Occasional Contributor
    Hi Jay,



    I have not understood this part of your code:

    GetTabRect(index)... Is there a method in test complete like this?

    I used your code but TC searches for GetTabRect(index) and could not find this object.

    How do I mention the rectangle area of tabs in xTabProject object? I got one property of xTabproject, which is 'DisplayRectangle', does this property shows Top,Left,Height,Width of Tabs? Is this of use in any way, here?



    I know Utils.Rect which returns a reference to a new empty rect object, but I dont know whther that would be useful here.
  • Hello Neha,


    GetTabRect is a method of the System.Windows.Forms.TabControl component. It looks like you are using a non-standard tab component since it does not provide the method. In this case, please let us know your control's name and version and the value of the ClrFullClassName property for the WinFormsObject("xTabProject") object.

  • neha_renukdas's avatar
    neha_renukdas
    Occasional Contributor

    ClrFullClassName: DevExpress.XtraTab.XtraTabControl 

    Version: 10.2.0.4 from Developer Express Inc.



  • Hello Neha,


    Here are the ClickRTab and DblClickTab functions that should work with your DevExpress control:




    function ClickRTab(tab_ctrl, index)



      var rect = tab_ctrl.ViewInfo.HeaderInfo.Rows.Item(0).Pages.Item(index).Bounds;     

      X = rect.Left + rect.Width/2;

      Y = rect.Top + rect.Height/2;

      tab_ctrl.ClickR(X, Y); 

    }


    function DblClickTab(tab_ctrl, index)



      var rect = tab_ctrl.ViewInfo.HeaderInfo.Rows.Item(0).Pages.Item(index).Bounds;     

      X = rect.Left + rect.Width/2;

      Y = rect.Top + rect.Height/2;

      tab_ctrl.DblClick(X, Y); 

    }


    Please pay attention to the way a page header's bounds are got using the control's internal properties. You can browse the internal properties in the Object Browser.