pythonpywinauto

Can't get print_control_identifiers() to work in a very basic scenario


Neither GUI element (wrapper) nor wrapper method 'print_control_identifiers' were found (typo?) error is returned for Application and DialogWrapper classes. WindowSpecification class returns None.

I was expecting the WindowSpecification to return at least something. Because a few milliseconds later I am able to interact with it. For example I successfully iterate like this: for child in self.main_window_specification.Children():

Code:

def run(self, output_mod_name):
        """ Runs the ArtManager executable """
        logger.info("Starting art manager")
        self.app = Application(backend="win32").start(self.path)
        logger.debug(f"Type of self.app: {type(self.app)}")
        try:
            logger.debug("This is expected to fail")
            logger.debug(f"{self.app.print_control_identifiers()}")
        except Exception as exc:
            traceback_formatted = traceback.format_exc()
            logger.debug(traceback_formatted)
        logger.debug("Launched art manager process")
        # wait for the window to come up
        expected_window_title = f"S: {output_mod_name} | A: {output_mod_name} | Art Manager"

        self.main_window_dialog = self.app.window(best_match=expected_window_title).wait('ready', timeout=10)
        logger.debug(f"Type of self.main_window_dialog: {type(self.main_window_dialog)}")
        try:
            logger.debug("This is expected to fail too")
            logger.debug(f"{self.main_window_dialog.print_control_identifiers()}")
        except Exception as exc:
            traceback_formatted = traceback.format_exc()
            logger.debug(traceback_formatted)

        logger.info("Art manager started")
        self.main_window_specification = self.app.window(best_match=expected_window_title)
        logger.debug(f"Type of self.main_window_specification: {type(self.main_window_specification)}")
        try:
            logger.debug("This is expected to work")
            logger.debug(f"{self.main_window_specification.print_control_identifiers()}")
        except Exception as exc:
            traceback_formatted = traceback.format_exc()
            logger.debug(traceback_formatted)
        logger.debug("Aquired handle on Art Manager window")

Output:

2023-10-09 12:21:24,756 - (art_manager.py:76) - tqma - INFO - Starting art manager
2023-10-09 12:21:26,007 - (art_manager.py:78) - tqma - DEBUG - Type of self.app: <class 'pywinauto.application.Application'>
2023-10-09 12:21:26,008 - (art_manager.py:80) - tqma - DEBUG - This is expected to fail
2023-10-09 12:21:26,008 - (art_manager.py:84) - tqma - DEBUG - Traceback (most recent call last):
  File "src\binary_automation\art_manager.py", line 81, in run
    logger.debug(f"{self.app.print_control_identifiers()}")
  File "pywinauto\application.py", line 180, in __call__
AttributeError: Neither GUI element (wrapper) nor wrapper method 'print_control_identifiers' were found (typo?)

2023-10-09 12:21:26,008 - (art_manager.py:85) - tqma - DEBUG - Launched art manager process
2023-10-09 12:21:26,021 - (art_manager.py:90) - tqma - DEBUG - Type of self.main_window_dialog: <class 'pywinauto.controls.hwndwrapper.DialogWrapper'>
2023-10-09 12:21:26,021 - (art_manager.py:92) - tqma - DEBUG - This is expected to fail too
2023-10-09 12:21:26,021 - (art_manager.py:96) - tqma - DEBUG - Traceback (most recent call last):
  File "src\binary_automation\art_manager.py", line 93, in run
    logger.debug(f"{self.main_window_dialog.print_control_identifiers()}")
AttributeError: 'DialogWrapper' object has no attribute 'print_control_identifiers'

2023-10-09 12:21:26,021 - (art_manager.py:98) - tqma - INFO - Art manager started
2023-10-09 12:21:26,022 - (art_manager.py:100) - tqma - DEBUG - Type of self.main_window_specification: <class 'pywinauto.application.WindowSpecification'>
2023-10-09 12:21:26,022 - (art_manager.py:102) - tqma - DEBUG - This is expected to work
2023-10-09 12:21:26,101 - (art_manager.py:103) - tqma - DEBUG - None
2023-10-09 12:21:26,101 - (art_manager.py:107) - tqma - DEBUG - Aquired handle on Art Manager window

Solution

  • Because app object doesn't have method dump_tree() or its alias print_control_identifiers(). It is a method of WindowSpecification object only. In future releases it will be added to a wrapper object as well. No plans for Application object though.

    But for Application and Desktop objects there is method windows() to return a list of top level windows as wrappers. Their properties/methods can be used to create proper WindowSpecification.

    EDIT: By default method dump_tree() prints to stdout / console. It can be redirected to a file by the method parameter filename. Yes, the method returns None. This is by design from the very beginning.