robocorp / rpaframework

Collection of open-source libraries and tools for Robotic Process Automation (RPA), designed to be used with both Robot Framework and Python
https://www.rpaframework.org/
Apache License 2.0
1.17k stars 225 forks source link

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

Open kkotenko opened 8 months ago

kkotenko commented 8 months ago

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.

https://github.com/robocorp/rpaframework/blob/3853cf79bad37c1f881e950a88f3f304c5d4a58e/packages/windows/src/RPA/Windows/keywords/window.py#L328-L345