-->

Windows GUI Automation on legacy app

2019-07-30 05:48发布

问题:

I'm trying to automate an old windows app called FacTel5.

I've been able to automate the login part but the next form is a bullet-like list whose controls are not showing, neither on pywinauto control_identifiers or Windows Inspect

from pywinauto.application import Application
app = Application(backend="uia").start(r'C:\Factel5\Factel5.exe')

controlAcceso = app.FacTel5['Control de acceso a FacTel5'].GroupBox

user = controlAcceso.child_window(auto_id="4", control_type="Edit")
user.type_keys("userid")

password = controlAcceso.child_window(auto_id="5", control_type="Edit")
password.type_keys("password")

controlAcceso.child_window(title="Aceptar", auto_id="3", control_type="Button").click()

pro = app.process
winApp = Application().connect(process=app.process)

App uses the "uia" backend and the winApp autoconnects using win32 backend.

The upper code lands me at this window, if you need/try the code by yourself the credentials are the proper ones (and they are defined on the program manual).

My objective is to click the 1st element of the list.

I really appreciate any help you can provide.

回答1:

These controls even don't react on keyboard actions. So the only solution is to click by coordinates! But stop! It's unreliable! If it's absolute screen coordinates, yes it is. But we may use relative coordinates (origin is a top-left corner of the control). It can be reliable if control sizes are fixed.

This code works for me on Win10 x64:

from pywinauto.application import Application

app = Application(backend="uia").start(cmd_line=r"C:\Program Files (x86)\Factel5\Factel5.exe")
# this main window spec should work even if the subtitle changes
main_window = app.window(title_re=u'FacTel5 - Telef\u0443nica.*')

controlAcceso = main_window['Control de acceso a FacTel5'].GroupBox
user = controlAcceso.Edit1
user.set_text("userid")
password = controlAcceso.Edit2
password.set_text("password")
controlAcceso.child_window(title="Aceptar", control_type="Button").click()

controlAcceso = main_window['Control de acceso a FacTel5'].child_window(title=u'\u0457Qu\u0439 desea hacer?')
# controlAcceso = main_window['Control de acceso a FacTel5'][u'\u0457Qu\u0439 desea hacer?'] # TODO: need a bug fix
rect = controlAcceso.rectangle()
item1 = (rect.width() / 2, int(float(rect.height() * 2.0) / 11.5))
item2 = (rect.width() / 2, int(float(rect.height() * 3.0) / 11.5))
item3 = (rect.width() / 2, int(float(rect.height() * 4.0) / 11.5))
item4 = (rect.width() / 2, int(float(rect.height() * 5.0) / 11.5))
item5 = (rect.width() / 2, int(float(rect.height() * 6.0) / 11.5))

item6 = (rect.width() / 2, int(float(rect.height() * 8.5) / 11.5))
item7 = (rect.width() / 2, int(float(rect.height() * 9.0) / 11.5))
item8_exit = (rect.width() / 2, int(float(rect.height() * 10.0) / 11.5))

# uncomment move_mouse and comment click_input to see where the click happens
# controlAcceso.move_mouse_input(coords=item1, absolute=False)
controlAcceso.click_input(coords=item1, absolute=False)

main_window.menu_select(u'Facturaciones->Gestión de facturaciones')