Getting value with pywinauto from text field

How to get the result from the text field of the ms calculator, which displays the result of any mathematical operations? Swapy (v.0.4.3) shows me that this text field has the value "Static2", after a simple run of the script I get an empty list. Here is 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 am I wrong?

+5
source share
1 answer

Try

 text = app.calc.Static3.window_text() 

As I see in Spy ++, Notepad.exe (version of Win7) has 4 static blocks. The third has non-empty text. Therefore, you need to identify it by the name "Static3" because "Static1" and "Static0" identify the same static field (which is a bit strange, yes - this is the pywinauto function).

For a more detailed study, use

 app.calc.print_control_identifiers() # or .dump_tree() 
+5
source

Source: https://habr.com/ru/post/1203083/


All Articles