如何使用pywinauto选中/取消选中列表框中的项目?

问题描述

我正在尝试使用pywinauto自动执行Cambium LINKPlanner应用程序,并找到了我所需的几乎所有控件。但是,有一个选中的列表框,其标识符为“ ListBox”,似乎没有任何方法可以选中/取消选中列表中的项目。

Screen shot of (checked) ListBox

我可以列出ListBox的内容:

>>> app.LINKPlanner.ListBox.item_texts()
['PMP 450b High Gain','PMP 450b Mid-gain','PMP450 (retired)','PMP450d (retired)','PMP450i','PMP450i ATEX/HAZLOC']

我可以按名称或位置突出显示列表框中的项目:

>>> app.LINKPlanner.ListBox.select('PMP450i')
<win32_control.ListBoxWrapper - '',ListBox,70154>
>>> app.LINKPlanner.ListBox.select(2)
<win32_control.ListBoxWrapper - '',70154>

但是我无法选中/取消选中列表项中的复选框。

有什么建议吗?

编辑:

使用瓦西里(Vasily)的建议,我能够看到边界框,然后使用click_input单击复选框。

>>> app.LINKPlanner.ListBox.select('PMP 450b High Gain').item_rect(0)
<RECT L0,T0,R276,B17>
>>> app.LINKPlanner.ListBox.select('PMP 450b High Gain').click_input(coords=(9,9))

解决方法

如果将其检测为ListBox,则可能是所有者绘制的复选框,无法单独检测。我建议先使用方法.item_rect(item_name),然后再使用方法.click_input()。同样,方法.client_to_screen()可能会有所帮助。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...