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>