问题描述
我是 python 和 pywinauto 的新手.尝试使用 SWAPY 在 pywinauto.controls.hwndwrapper.hwndwrapper 中设置或获取 TextBox(windows 控件)的文本,我有包装类的类名.如何在pywinauto中使用类名(如Afx:633C0000:1008
)访问包装类内部的控件?
导入pywinauto导入 pywinauto.controls从 pywinauto.application 导入应用程序app = Application().Connect(title=u'SAP', class_name='SAP_FRONTEND_SESSION')sapfrontendsession = app.SAPafxe = sapfrontendsession[u'Afx:633C0000:1008']
pywinauto 提供了基于 WindowSpecification
和包装器的 2 级概念.窗口规范只是一个描述,一组搜索所需控件的标准(在创建 WindowSpecification
时它可能不存在).如果找到,则为真正存在的控件创建具体的包装器.在空闲控制台中它看起来是这样的:
窗口规范不能超过 2 个级别:app.WindowName.ControlName
.可以指定更详细的搜索条件:
app.window(title=u'SAP', class_name_re='^Afx:.*$')app.SAP.child_window(class_name='Edit')
可能的 window/child_window
参数与 find_elements.
附言伟大的 Python 功能可以隐藏生产代码中的 wrapper_object()
方法调用,因此您只需要出于调试目的调用它.例如这些语句是等效的(做同样的事情):
app.WindowName.Edit.set_text(u'text')app.WindowName.Edit.wrapper_object().set_text(u'text')
但是下面的语句返回不同的对象:
app.WindowName.Edit # app.WindowName.Edit.wrapper_object() # <EditWrapper>
I am new to python and pywinauto. Trying to set or get Text for TextBox (windows control) inside pywinauto.controls.hwndwrapper.hwndwrapper by using SWAPY, I have Class Name of wrapper class. How to access controls inside wrapper class using class name (like Afx:633C0000:1008
) in pywinauto?
import pywinauto
import pywinauto.controls
from pywinauto.application import Application
app = Application().Connect(title=u'SAP', class_name='SAP_FRONTEND_SESSION')
sapfrontendsession = app.SAP
afxe = sapfrontendsession[u'Afx:633C0000:1008']
pywinauto provides a 2-level concept based on WindowSpecification
and wrappers. Window specification is just a description, set of criteria to search desired control (it may not exist when WindowSpecification
is created). Concrete wrapper is created for really existing control if found. In IDLE console it looks so:
>>> app.RowListSampleApplication
<pywinauto.application.WindowSpecification object at 0x0000000003859B38>
>>> app.RowListSampleApplication.wrapper_object()
<pywinauto.controls.win32_controls.DialogWrapper object at 0x0000000004ADF780>
Window specification can have no more than 2 levels: app.WindowName.ControlName
. It can be specified with more detailed search criteria:
app.window(title=u'SAP', class_name_re='^Afx:.*$')
app.SAP.child_window(class_name='Edit')
Possible window/child_window
arguments are the same as listed in find_elements.
P.S. Great Python features can hide wrapper_object()
method call in production code so you need to call it for debugging purpose only. For example these statements are equivalent (do the same):
app.WindowName.Edit.set_text(u'text')
app.WindowName.Edit.wrapper_object().set_text(u'text')
But the statements below return different objects:
app.WindowName.Edit # <WindowSpecification>
app.WindowName.Edit.wrapper_object() # <EditWrapper>
这篇关于无法访问 pywinauto 的 hwndwrapper(包装类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!