Forum Discussion

nem's avatar
nem
Occasional Contributor
13 years ago

The direction FindChild method works

Hello,

I wonder how FindChild method searches an object. Particularly I’m interested in direction (e.g. from top to down, from left to right?).



For example I have four objects at the same level relative to parent object.

Parent.

-   name=Child1

-   name=Child2

-   name=Child3

-   name=Child4

Each of them applies to the same search criteria. Let's say parent.FindChild("name","Child*")





So, I wonder which will be returned.





Thanks in advance.

6 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    FindChild, with that layout, would return Child1... I believe it just returns the first one found.  To find a SPECIFIC one, you'd need to pass into FindChild an array of properties and corresponding array of values to find the particular child you're looking for.



    Another method to use is to use FindChildren which will return an array of child objects that you can then iterate through to find the specific one you want.
  • nem's avatar
    nem
    Occasional Contributor
    Robert, Alex thanks for your answers.

    But the question is not in how find and separate child object. Not technical aspect - it's easy :).

    I just wanted to understand search sequence. My first idea was the same as Robert wrote. But it seems that it works vice-versa (it returned Child4) after I did a short experiment.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    You know, you're right.  I recall working with a similar situation elsewhere and it did return in what appeared to be reverse order.  The only explanation I have is that is the order in which the objects are found and recognized by TestComplete and, therefore, the order in which they are returned. 

  • Hi Aliaksei,





    The first found object that correspongs to the search criteria is returned. But this object can be different at each test start. This depends on various technical reasons.
  • nem's avatar
    nem
    Occasional Contributor
    >>>This
    depends on various technical reasons - that's particularly what I'm trying to find out :) .



    Anyway, thanks for your answers.