Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPA.Windows: Not possible to close a window after a popup of it has been closed #1161

Open
kkotenko opened this issue Mar 22, 2024 · 0 comments

Comments

@kkotenko
Copy link
Contributor

A Win32 Framework application may open a modal window (ControlType Window, ClassName #32770). At least in the example I am facing, it has the same ProcessId as the main application.

Therefore, closing a popup that has been Control windowed is not possible using Close Current Window - Close Current Window just kills the whole process via SIGTERM (in this case, including the main application, because they share ProcessId). The popup has to be closed by other means (e.g. by sending an ESC keystroke).

However, that means self.window still points to the now closed popup. It is a WindowsElement object, whose item has a ProcessId of 0.

When you try to call Close current window later, you are therefore sending a SIGTERM to PID 0 (which is the idle process), which throws an OSError: [WinError 87] The parameter is incorrect.

The solution, obviously, is to re-take control of the main application after the popup has been closed. However, I wonder whether this deserves more documentation somewhere, or adding error messages to catch the case of attempting to close PID 0.

window = self.window
if window is None:
self.logger.warning("There is no active window!")
self.ctx.window_element = None
return False
pid = window.item.ProcessId
self.logger.info("Closing window with name: %s (PID: %d)", window.name, pid)
os.kill(pid, signal.SIGTERM)
self.ctx.window_element = None
anchor = self.ctx.anchor_element
if anchor and window.is_sibling(anchor):
# We just closed the anchor as well (along with its relatives), so clear
# it out properly.
self.ctx.clear_anchor()
return True

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

No branches or pull requests

1 participant