Skip to content

fix: handle COMError in wait_enabled when UI element becomes stale#324

Open
nuthalapativarun wants to merge 1 commit intomicrosoft:pre-releasefrom
nuthalapativarun:fix/wait-enabled-com-error
Open

fix: handle COMError in wait_enabled when UI element becomes stale#324
nuthalapativarun wants to merge 1 commit intomicrosoft:pre-releasefrom
nuthalapativarun:fix/wait-enabled-com-error

Conversation

@nuthalapativarun
Copy link
Copy Markdown

Summary

Selecting an item from a dropdown (or any interaction that triggers a UI state change) can invalidate the underlying COM automation element. The subsequent is_enabled() poll in wait_enabled() then raises a COMError and crashes the agent loop:

_ctypes.COMError: (-2147220991, 'An event was unable to invoke any of the subscribers', ...)

Traceback from the issue:

File "ufo/automator/ui_control/controller.py", line 346, in wait_enabled
    while not self.control.is_enabled():
_ctypes.COMError: (-2147220991, ...)

Changes

  • Wrapped the is_enabled() call in wait_enabled() inside a try/except Exception block in ufo/automator/ui_control/controller.py
  • On any exception (including COMError), logs a warning and breaks out of the wait loop, treating the element as ready
  • The timeout logic is preserved for the non-exception path

Testing

Reproduced by selecting an option from a dropdown menu in an application that triggers a UI rebuild. The fix allows the agent to continue execution after dropdown selection instead of crashing.

Closes #246

Selecting an option from a dropdown (or any interaction that triggers
a UI change) can invalidate the underlying COM element.  The subsequent
call to control.is_enabled() then raises:

  _ctypes.COMError: (-2147220991, 'An event was unable to invoke any
  of the subscribers', ...)

Wrap the is_enabled() poll in a try/except so that a stale-element
COM error is treated as "ready" (with a warning) rather than crashing
the agent loop.

Closes microsoft#246
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant