旧应用程序上的 Windows GUI 自动化 [英] Windows GUI Automation on legacy app
问题描述
我正在尝试自动化一个名为
我的目标是点击列表的第一个元素.
非常感谢您能提供的任何帮助.
这些控件甚至对键盘操作没有反应.所以唯一的解决办法就是按坐标点击!但是停下来!不靠谱!如果是绝对屏幕坐标,是的.但是我们可以使用相对坐标(原点是控件的左上角).如果控件大小固定,则它是可靠的.
此代码在 Win10 x64 上适用于我:
from pywinauto.application import Applicationapp = Application(backend="uia").start(cmd_line=r"C:\Program Files (x86)\Factel5\Factel5.exe")# 即使字幕更改,此主窗口规范也应该有效main_window = app.window(title_re=u'FacTel5 - Telef\u0443nica.*')controlAcceso = main_window['Control de acceso a FacTel5'].GroupBox用户 = controlAcceso.Edit1user.set_text("userid")密码 = controlAcceso.Edit2password.set_text("密码")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:需要修复错误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))# 取消注释 move_mouse 和注释 click_input 以查看点击发生的位置# 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')
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.
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')
这篇关于旧应用程序上的 Windows GUI 自动化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!