Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 782
Rustam Ivanoff Avatar asked Sep 21 '14 16:09

Rustam Ivanoff


People also ask

What can pywinauto do?

pywinauto is a set of python modules to automate the Microsoft Windows GUI. At its simplest it allows you to send mouse and keyboard actions to windows dialogs and controls.

How do I close an application in pywinauto?

You can check to see if there's a specific hotkey to close the program. However, the easiest way to do this is to send Alt-F4.


1 Answers

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()
like image 197
Vasily Ryabov Avatar answered Dec 30 '22 21:12

Vasily Ryabov