首页 > 解决方案 > 如何使用 pywinauto 选中/取消选中 ListBox 中的项目?

问题描述

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

(选中)列表框的屏幕截图

我可以列出 ListBox 的内容:

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

我可以通过名称或位置突出显示 ListBox 中的项目:

>>> app.LINKPlanner.ListBox.select('PMP450i')
<win32_control.ListBoxWrapper - '', ListBox, 70154>
>>> app.LINKPlanner.ListBox.select(2)
<win32_control.ListBoxWrapper - '', ListBox, 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))

标签: listboxpywinautocheckedlistbox

解决方案


如果检测为ListBox,则可能是自绘复选框,无法单独检测。我建议使用 method.item_rect(item_name)然后 method .click_input()。方法.client_to_screen()也可能有帮助。


推荐阅读