如何使用 pywinauto 选择没有标题的组合框

问题描述 投票:0回答:1

在我的 Windows 应用程序中,有三个没有标题但有不同列表项的组合框。如何根据 ComboBox 包含的项目选择正确的 ComboBox。如果我只选择 Control_Type,我会收到 ElementAmbigouslyError。

我收到错误:-

pywinauto.findwindows.ElementAmbigouslyError:有 3 个元素 匹配条件 {'control_type': 'ComboBox', 'top_level_only': False,'父级':,'后端':'uia'}


from pywinauto.application import Application
from pywinauto.mouse import click
import time


# Path to the application executable
app_path = r"file path"

# Start the application
app = Application(backend='uia').start(app_path)

# Wait for the main window to appear (adjust timeout as needed)
main_window = app.window(title_re="ApplicationName")
# Now you can interact with the main window or its controls as needed
# Example: print the main window's text
print(main_window.window_text())

# Example: click a button in the main window
main_window.child_window(title="System.Windows.Controls.ListViewItem", auto_id="Alarm", control_type="ListItem").click_input()
time.sleep(1)

main_window.child_window(control_type="ComboBox").click_input()
python combobox pywinauto
1个回答
0
投票

解决方法只是在搜索条件中使用

found_index

main_window.child_window(control_type="ComboBox", found_index=0).click_input()

对于您的情况,索引可以是 0、1 或 2。您可以通过方法

.draw_outline()
而不是
.click_input()
来仔细检查找到的组合框。

© www.soinside.com 2019 - 2024. All rights reserved.