Forum Discussion

ZXQA's avatar
ZXQA
Occasional Contributor
5 years ago

Finding an object when form name changes but every form has the same object

Hello,

   This explanation may be poor but I am trying to script this for the first time.

I have an object that I need to interact with regardless of what form I am on. I have tried to use the example provided by support but I cannot get it to work. There is a label on every form in our application that when click can navigate to the main form of the application.  

 

Sys.Process("Signon").WinFormsObject("#######").WinFormsObject("LeftPanel").WinFormsObject("labLogo")

 

The WinFormsObject("######") changes with every form but it is always the ending WinformsObject("labLogo"). When I use Find it finds the object but on the Sys.Process("Signon"). I need it to find the object on whatever the current form is and take action against it. I have tried everything I could think of using the support and community to no avail.  I am using VBScript if that changes anything.

 

Thank you for any help!!!

 

 

 

 

  • Hi,
    It will be very easy for you if you use NameMapping inside TestComplete.

    It is not recommended to use Sys. to write scripts in TestComplete,

     

    Use NameMapping -> modify recommended property with (use wild cards):

    https://support.smartbear.com/testcomplete/docs/reference/misc/using-wildcards.html

     

    Also,

    Use .Find() on the selected object to avoid performance problems. It is not recommended to start the search process from the beginning of the program object structure.

     

    Debug ๐Ÿ›this piece of code and change parameters. This is the key to success.

  • ZXQA's avatar
    ZXQA
    Occasional Contributor

    Additional info:

     

    This is the sample I am trying to use and I feel like my issue is with the "Set p =". I have tried to use wild cards like (Sys.Process("Signon").WinFormsObject("*").WinFormsObject("LeftPanel").WinFormsObject("labLogo")

    but that does not work. I have also tried findChild but it still finds the wrong control and cannot access it because it is not visible.

     

    sub findTest
    Dim p, control
    ' Searches for the control
    Set p = Sys.Process("Signon")
    Set control = p.Find("WinFormsControlName", "labLogo", 1000)
    ' Processes the search results
    If control.Exists Then
    Log.Message control.FullName
    Else
    Log.Error "The object was not found."
    End If
    End Sub

    • Wamboo's avatar
      Wamboo
      Community Hero

      Hi,
      It will be very easy for you if you use NameMapping inside TestComplete.

      It is not recommended to use Sys. to write scripts in TestComplete,

       

      Use NameMapping -> modify recommended property with (use wild cards):

      https://support.smartbear.com/testcomplete/docs/reference/misc/using-wildcards.html

       

      Also,

      Use .Find() on the selected object to avoid performance problems. It is not recommended to start the search process from the beginning of the program object structure.

       

      Debug ๐Ÿ›this piece of code and change parameters. This is the key to success.