且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

pywinauto qwidget 点击触发无动作

更新时间:2022-10-15 09:10:56

Qt 应用可以使用 Application(backend='uia') 自动化.请阅读专为 pywinauto 0.6.0+ 编写的入门指南新后端.它解释了核心概念和许多有用的技巧.

附言我已经下载了这个精简版的应用程序,稍后会尝试为您制作一个示例.

It is visibly that a QWidget button is pressed and released, unfortunately no action is triggered.

The environment is similar to find qwidget object text by using pywinauto. The code has resorted to use of absolute coordinates from How to click a 'next' button of a window using python.

Once the program runs, the target window will get focus. The cursor starts to be somewhere close to the center of the target window. Then it moves to the button, presses the button since the color changes to the down-color. Then it releases the button, and the cursor moves back to the center of window. Only one thing missing, no action is taken from the target window application.

There is one fix: If I move the mouse to the title of the window and click at the right time, the automatic click on the button will trigger a real action. This makes me puzzled as to why this is happening, and unable to think about a solution for it.

app1 = Application()
app1.connect(title_re='^Quartus Prime Programmer.*$')
app1.QWidget.print_control_identifiers()

win1 = app1.QWidget
rect1 = win1.rectangle()
coor1 = (rect1.left+64,rect1.top+350) # 64, 350: "add file"
win11 = win1.TopLevelParent()
for i in range(3):
    win11.SetFocus()
    win11.PressMouseInput(coords=coor1)
    time.sleep(1.3)
    win11.ReleaseMouseInput()
    time.sleep(3.0)

The code repeats it three time so a human intervention can be easily inserted into the process.

Qt apps can be automated using Application(backend='uia'). Please read the Getting Started Guide written specially for pywinauto 0.6.0+ with the new backend. It explains the core concept and many useful tricks.

P.S. I've downloaded this Lite edition app and will try to make an example for you later.