[请教]pywinauto 和 clicknium 对于 pane 控件是怎么访问的 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
873792861
V2EX    Python

[请教]pywinauto 和 clicknium 对于 pane 控件是怎么访问的

  •  
  •   873792861 2023-05-29 18:10:07 +08:00 1513 次点击
    这是一个创建于 902 天前的主题,其中的信息可能已经有所发展或是发生改变。

    如题,我刚开始学这些 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" /> 

    有了解的网友可以指点下我怎么处理这个吗?因为我谷歌了好多,都没找到答案

    目前尚无回复
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2332 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 33ms UTC 15:39 PVG 23:39 LAX 07:39 JFK 10:39
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86