Forum Discussion

purushindeed01's avatar
purushindeed01
Occasional Contributor
10 years ago

how to make use of waitchild and find child

Hi,

  i appriciate if  you would give explanation with example , hoe to  use the  waitchild and findchild methods.

 how to count no of sub  links present in a main link and i want to use for loop to work on any of this sublink ratehr than going for each and every link.

           thank you,

5 Replies

    • ameykhopade's avatar
      ameykhopade
      Contributor

      HI,

       

      hi trying to evaluate and object and i am using findchild property in that can i use 2 property name and 2 property values.

       

      like

      Sys.Browser("iexplore").Page("*").Form("aspnetForm").Panel(0).Panel("cphActionsLeft_ddSavedFilters_DropDown").Panel(0).FindChild(["contentText","ObjectIdentifier"],["All Overdue Inspections,"1"],2) 

       

      can i use this ?

       

      sorry that i have asked this doubt in the existing link. but found a good example of findchild method thus asking here.

       

      Thanks,

      Amey

  • Ravik's avatar
    Ravik
    Super Contributor
    Hi purush reddy,



    Please refer how to use find Child method -



    1- Find : - This method is used to search the object from the TestedObj hierarchy.This method searches an object with the specified values of the specified properties. here search starts from TestedObj parent node and continue upto the depth mention.

    Syntax


         


           Set myObject = TestObject.Find(PropertyName, PropertyValue, Depth)        


     


     


    Example - Suppose I want to search "gmail link" on google page, So I will write code as below


     


    Set lnkgmail = Sys.Browser("IExplorer").Page("google.com").Find("ContentText", "gmail", 10) 


     


    Here - 


    1- Property Name = ContentText


    2- Property Value = gmail


    3- Depth = 10


     


    2- FindChild : - A TestedObj may have one or more child objects with specified values of the specified properties so in this case we will using FindChild Method. FindChild method searches  child objects from the TestedObj.

    Syntax -




               Set myObject = TestObject.FindChild(PropertyName, PropertyValue, Depth)    


     


    Note - The difference between Find and FindChild is that, FindChild searches child objects, while Find searches TestedObj only.


     


    3- FindAll : - FindAll method is used to search desire object from the TestedObj hierarchy. FindAll Method searches the entire object that have Specified value of the Specified properties. it's return a collection of objects and stored entire object list into an Array.


    Syntax -


         

           Set myObject = TestObject.FindChild(PropertyName, PropertyValue, Depth)   




    4- FindAllChildren : – FindAllChildren method is same as FindAll method (as mention above), it will search all the children and store them into an Array.




    Set myObject = TestObject.FindAllChildren(PropertyName, PropertyValue, Depth)   




    Note - We can search a object with the combination of multiple properties and values. Suppose we want to search gmail link which is enabled on page, so in this case we will need to define arrays for Property Name and Property Value and use them like below-

    Example

        

      PropertiesName = Array ("ContentText","ObjectType", "Enabled")

      PropertieValue = Array("gmail","Link", "True")



     Set myObject = TestObject.FindChild(PropertiesName, PropertieValue, 100)     





    5- ChildCount : - An application, TestedObj may have one or more child like Processes is a child of Sys , Windows/Page is a child of process and so on. ChildCount property returns the number of children of the TestedObj.


    Syntax -


           getChildCount  = TestObject.ChildCount    





    6 waitchild -




    This method delays script execution until the specified child object appears in the child list or the specified time limit is reached. let consider in your page you have a "Site Map" item at bottam of the page, so first you create a object for "Site Map" using Find, FindChild, FindAll, FindAllChildren as explain above.



    Now suppose you want to delay script execution until "Site Map" is not loaded at that time you can use this method



    If TestObject.WaitChild(YourObjName, 300).Exists Then

      ' Child object exists

    Else

      ' There is no such a child

    End If



    Thanks




  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Purush,


     


    There are many ways to count the links from a panel or a page. The code below uses the EvaluateXPath method that searches for HTML's A tag on a page:




    function LinkCounter()


    {


      var page = NameMapping.Sys.Browser("chrome").Page("http://smartbear.com/forums/");


      page.Form("form").Panel("container").Panel(1).Panel(0).Nav(0).Link(0).Click();


     


      var panel = page.Form("form").Panel("container").Panel(1).Panel(0).Nav(0).Panel(0).Panel(0).Panel(3);


      var tmp = panel.EvaluateXPath("//A");


      if (tmp != null)


      {


        // Convert the array to the JScript-compatible format 


        var links = (new VBArray(tmp)).toArray();


        Log.Message("Number of liks: " + links.length);


      }


    }




     


    Refer to the "Finding Web Objects Using XPath Expressions" article for details.