Forum Discussion

ibeard's avatar
ibeard
Occasional Contributor
9 years ago
Solved

Call Windows Form function based on string

This may seem strange, but I am trying to create a python script interface to use with my Keyword Tests. To do this I need to be able to pass in the grid control of any screen within our product. The problem I have is that the only way to perform a DoubleClick on our custom controls is to directly call the event function on the Form itself. This does work, but it requires me to explicitly type out the function in the script. Is it possible to have TestComplete call a function in a Form based on a string as input? I am thinking something similar to using getattr() in python.

 

Thank you

 

  • You can use getattr built-in function.

    def main():
      obj = Sys.Process("notepad", 2).Window("Notepad", "Untitled - Notepad", 1).Window("Edit", "", 1)
      callClickMethod(obj, True, -1, -1)
      callClickMethod(obj, False, -1, -1)
    
    def callClickMethod(obj, dbl, x, y):
      getattr(obj, "DblClick" if dbl else "Click")(x, y)
    

2 Replies

  • Silmaril's avatar
    Silmaril
    SmartBear Alumni (Retired)

    You can use getattr built-in function.

    def main():
      obj = Sys.Process("notepad", 2).Window("Notepad", "Untitled - Notepad", 1).Window("Edit", "", 1)
      callClickMethod(obj, True, -1, -1)
      callClickMethod(obj, False, -1, -1)
    
    def callClickMethod(obj, dbl, x, y):
      getattr(obj, "DblClick" if dbl else "Click")(x, y)
    
  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Hi Ian,

     

    It sounds like you need aqObject.CallMethod:

    aqObject.CallMethod(obj, "methodname", param1, param2, ...)