
如题,我刚开始学这些 ui 自动化的库,没想到,刚开始就遇到问题了。因为我用的是 Windows11 ,notepad 是支持多标签页。如此一来,在 demo 就遇到了问题: 我不知道如何访问标签页的菜单,代码如下:
from pywinauto import WindowSpecification from pywinauto.application import Application app = Application(backend='uia') app.connect(process=17200) dlg: WindowSpecification = app.window(class_name='Notepad') dlg.ty dlg.print_control_identifiers() menubar: WindowSpecification = dlg.child_window(title="文件", control_type="MenuItem", found_index=0) menubar.click_input() 输出的控件信息只到 menubar 那里,标签页的,比如点击 [文件] 按钮点击后展开一个菜单,这个我就不知道怎么访问弹出菜单的 [打开] 那个按钮了。虽然可以使用发送快捷键的方式打开,但我想知道怎么去访问。以下是输出的控件信息:
Dialog - '无标题 - Notepad' (L0, T26, R1920, B1024) ['Dialog', '无标题 - NotepadDialog', '无标题 - Notepad'] child_window(title="无标题 - Notepad", control_type="Window") | | Pane - '' (L46, T36, R333, B68) | ['Pane', '无标题 Pane', 'Pane0', 'Pane1', '无标题 Pane0', '无标题 Pane1'] | | | | TabControl - '' (L46, T36, R333, B68) | | ['无标题 TabControl', 'TabControl', 'TabControl 添加新标签页'] | | child_window(auto_id="Tabs", control_type="Tab") | | | | | | ListBox - '' (L48, T36, R298, B68) | | | ['无标题 ListBox', 'ListBox'] | | | child_window(auto_id="TabListView", control_type="List") | | | | | | | | TabItem - '无标题. 未修改。' (L50, T36, R296, B68) | | | | ['TabItem', '无标题. 未修改。TabItem', '无标题. 未修改。'] | | | | child_window(title="无标题. 未修改。", control_type="TabItem") | | | | | | | | | | Static - '无标题' (L63, T44, R99, B59) | | | | | ['无标题 Static', 'Static', '无标题', 'Static0', 'Static1'] | | | | | child_window(title="无标题", control_type="Text") | | | | | | | | | | Button - '关闭标签页' (L255, T40, R287, B64) | | | | | ['Button', '关闭标签页 Button', '关闭标签页', 'Button0', 'Button1'] | | | | | child_window(title="关闭标签页", auto_id="CloseButton", control_type="Button") | | | | | | Button - '添加新标签页' (L301, T41, R333, B65) | | | ['Button2', '添加新标签页', '添加新标签页 Button'] | | | child_window(title="添加新标签页", auto_id="AddButton", control_type="Button") | | Pane - '' (L6, T68, R1914, B101) | ['Pane2', '无标题 Pane2'] | | | | Menu - '' (L6, T68, R174, B100) | | ['Menu', '无标题 Menu', 'Menu0', 'Menu1'] | | child_window(auto_id="MenuBar", control_type="MenuBar") | | | | | | MenuItem - '文件' (L10, T68, R58, B100) | | | ['文件 MenuItem', 'MenuItem', '文件', 'MenuItem0', 'MenuItem1'] | | | child_window(title="文件", control_type="MenuItem") | | | | | | MenuItem - '编辑' (L66, T68, R114, B100) | | | ['编辑', '编辑 MenuItem', 'MenuItem2'] | | | child_window(title="编辑", control_type="MenuItem") | | | | | | MenuItem - '查看' (L122, T68, R170, B100) | | | ['查看', 'MenuItem3', '查看 MenuItem'] | | | child_window(title="查看", control_type="MenuItem") | | | | Button - '设置' (L1876, T69, R1906, B99) | | ['Button3', '设置', '设置 Button'] | | child_window(title="设置", auto_id="SettingsButton", control_type="Button") | | Pane - '' (L6, T986, R1914, B1018) | [' 行 1 ,列 1Pane', 'Pane3'] | | | | Static - ' 行 1 ,列 1' (L21, T995, R80, B1011) | | [' 行 1 ,列 1', 'Static2', ' 行 1 ,列 1Static'] | | child_window(title=" 行 1 ,列 1", auto_id="ContentTextBlock", control_type="Text") | | | | Static - ' 100%' (L1545, T995, R1577, B1011) | | [' 100%', 'Static3', ' 100%Static'] | | child_window(title=" 100%", auto_id="ContentTextBlock", control_type="Text") | | | | Static - ' Windows (CRLF)' (L1633, T995, R1724, B1011) | | [' Windows (CRLF)', ' Windows (CRLF)Static', 'Static4'] | | child_window(title=" Windows (CRLF)", auto_id="ContentTextBlock", control_type="Text") | | | | Static - ' UTF-8' (L1793, T995, R1829, B1011) | | [' UTF-8Static', 'Static5', ' UTF-8'] | | child_window(title=" UTF-8", auto_id="ContentTextBlock", control_type="Text") | | TitleBar - '' (L0, T0, R0, B0) | ['TitleBar'] | | | | Menu - '系统' (L8, T34, R30, B56) | | ['系统 Menu', '系统', 'Menu2', '系统 0', '系统 1'] | | child_window(title="系统", uto_id="MenuBar", control_type="MenuBar") | | | | | | MenuItem - '系统' (L8, T34, R30, B56) | | | ['MenuItem4', '系统 MenuItem', '系统 2'] | | | child_window(title="系统", control_type="MenuItem") | | | | Button - '最小化' (L1775, T27, R1822, B57) | | ['Button4', '最小化 Button', '最小化'] | | child_window(title="最小化", control_type="Button") | | | | Button - '最大化' (L1822, T27, R1868, B57) | | ['Button5', '最大化 Button', '最大化'] | | child_window(title="最大化", control_type="Button") | | | | Button - '关闭' (L1868, T27, R1915, B57) | | ['Button6', '关闭', '关闭 Button'] | | child_window(title="关闭", control_type="Button") 后来,我想用 clicknium 试试,然后我试了下,发现这个库的录制的路径也是不行的。代码如下:
import subprocess from clicknium import locator,ui process=subprocess.Popen('notepad') ui(locator.notepad.document_文本编辑器).set_text('你好') 报错提示:clicknium.common.models.exceptions.ElementNotFoundError: Element can not be found. 录制的路径是这样子:
<ApplicatiOnfilePath="Notepad.exe" processName="Notepad" version="1.3" /> <UiaclassName="Notepad" isDirectChild="True" name="无标题 - Notepad" role="window" /> <UiaclassName="NotepadTextBox" role="pane" /> #这里验证没能通过 <UiaclassName="RichEditD2DPT" isDirectChild="True" name="文本编辑器" role="document" /> 有了解的网友可以指点下我怎么处理这个吗?因为我谷歌了好多,都没找到答案