Search code examples
python-2.7pywinauto

Getting value using pywinauto from text field


How to get result from ms calculator text field, which displays result of any math operations? Swapy (v.0.4.3) shows me that this text field has value of 'Static2', after running so simple script i get empty list. Here my code:

from pywinauto import *
n=[]
app=Application()
app.start_("calc.exe")
app.calc.Button11.ClickInput()
app.calc.Button20.ClickInput()
app.calc.Button11.ClickInput()
app.calc.Button21.ClickInput()
n=app.calc.Static2.Texts()#here i expected to get the number
print n

Where i did wrong?


Solution

  • Try

    text = app.calc.Static3.window_text()
    

    As I can see in Spy++, Notepad.exe (Win7 version) has 4 static boxes. The third one has non-empty text. So you need to identify it by "Static3" name, because "Static1" and "Static0" identifies the same static box (that's a bit strange, yes - it's pywinauto feature).

    For more detailed investigation use

    app.calc.print_control_identifiers() # or .dump_tree()