5

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?

2 Answers2

6

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()
Vasily Ryabov
  • 9,386
  • 6
  • 25
  • 78
  • PrintControlIdentifiers() gives me the same info as swapy did about name of this textfield and unfortunately your code changed nothing. By the way, why you are talking about notepad ;) and what is Spy++? Is it swapy analogue? – Rustam Ivanoff Sep 22 '14 at 19:22
  • Spy++ is a tool distributed with MS Visual Studio. How many statics are printed by PrintControlIdentifiers() ? Just try Static1, Static2, Static3, Static4 step by step. One of these should contain right text. – Vasily Ryabov Sep 23 '14 at 09:08
  • `app.calc.Window_(class_name='Static', ctrl_index=5).WindowText()` should help with guarantee. I've checked it right now. – Vasily Ryabov Sep 23 '14 at 09:17
  • Oh, yeah. :) I typed "Notepad.exe" but thought about "calc.exe", of course. – Vasily Ryabov Sep 23 '14 at 09:31
  • WindowText() Working well with python 3.5 and pywinauto 6.0 – EndermanAPM Jan 18 '17 at 11:15
0

I may be late to the party but I'm sure this will be handy, Lets say your control textbox is of edit type then you can easily do....

text = app.calc.Static3.get_value()

This is available in - pywinauto 0.6.8

Dev
  • 2,739
  • 2
  • 21
  • 34