Forum Discussion

swetha_adama's avatar
10 years ago

Creating Objects in Script- TestComplete unable to find objects

Hi All,



I have been trying to create objects and assign properties in Script without using Objects from Object Browser (recorded). Goal is to declare objects in Script and then define functions that will find and call the objects at runtime.



I am looking to find a syntax that is similar to Description.Create on QTP like below.



Sub Objects

Set FPWindow = Description.Create

FPWindow("Name").Value ="WPFObject("Shell", "FocusPoint", 1)"

FPWindow("Id").Value = "1"

End Sub



Test Complete did not find the above FPWindow object.



I also tried CreateObject as below but that is also not working


Sub Objects

  Dim FPWindow



  Set FPWindow=CreateObject("Name:=WPFObject("Shell", "FocusPoint", 1)","Id:=1"

End Sub



TestComplete is not finding objects created in the above manner.



Kindly Advise.

 


  • Hi Swetha,



    TestComplete provided below methods for Descriptive Programming please find this may help you. (All this methods help you to find objects at Run Time)





    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)     







    Ravik

  • Ravik's avatar
    Ravik
    Super Contributor
    Hi Swetha,



    TestComplete provided below methods for Descriptive Programming please find this may help you. (All this methods help you to find objects at Run Time)





    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)     







    Ravik