Unable to access windows controls inside pywinauto's hwndwrapper (wrapper class

拜拜、爱过 提交于 2019-12-13 05:34:11

问题


enter image description hereI 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']

回答1:


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.WrapperObject()
<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.ChildWindow(class_name='Edit')

Possible Window_/ChildWindow arguments are the same as listed in find_windows.


P.S. Great Python features can hide WrapperObject() 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.SetText(u'text')
app.WindowName.Edit.WrapperObject().SetText(u'text')

But the statements below return different objects:

app.WindowName.Edit # <WindowSpecification>
app.WindowName.Edit.WrapperObject() # <EditWrapper>


来源:https://stackoverflow.com/questions/35332670/unable-to-access-windows-controls-inside-pywinautos-hwndwrapper-wrapper-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!