-2

In my current work, I need to automate tests for a 3rd party Windows based logic programming app. 1) I want to start an application, 2) Specify the window to work on, 3) Find all the controls and properties 4) Finally get the output values from the controls Can someone please help? Thanks!

Here is my code:

#import the pywinauto.application module
from pywinauto.application import Application 
# create an applicaiton instance and execute the application
app = Application(backend="uia").start('calc.exe')  
# creating window specification
dlg_spec = app.window(title='Calculator')
# window lookup to deal with the window/control
dlg_spec.wrapper_object().minimize()
dlg_spec.minimize()
# Printing the control identifiers
app.Properties.print_control_identifiers()

I get TimeoutError and ElementNotFoundError (on Line 4)

Hossain
  • 235
  • 1
  • 3
  • 15
  • Can I use PyWinAuto for this? I tried but could not retrieve the UI controls to find the output value of a logic operation? – Hossain Aug 27 '18 at 20:36
  • pywinauto is powerful, but be careful which backend you use. This is all described in the [Getting Started Guide](https://pywinauto.readthedocs.io/en/latest/getting_started.html) in first two chapters. If you stuck at some step, please provide more details. Kind of app, used backend, code sample and output would be very useful. Otherwise it's hard to understand the problem. – Vasily Ryabov Aug 28 '18 at 09:00
  • Thanks Vasily! I have switched to the UIA backend and able to see all the controls. Now I have the basic question as I am learning from the scratch. How can I extract the output from a control box (in my logic program its an operation, let say addition operation) for given inputs. Please help me regarding this! – Hossain Aug 29 '18 at 17:59
  • It depends on control type. Usually method .window_text() helps. But for some controls it’s .get_value() or even .legacy_properties(). – Vasily Ryabov Aug 29 '18 at 18:19
  • Before diving deep into the tool, may I also ask what is difference between PyWinAuto and Winium. As a beginner, which one will be better for this task? – Hossain Aug 29 '18 at 20:35
  • It depends which language do you prefer. Winium also uses MS UI Automation API under the hood. There are few C# tools for this technology: White, Winium, FlaUI (written by former White maintainer) and WinAppDriver (from Microsoft, integrated with Appium). I’m maintaining rating of desktop GUI automation tools: https://github.com/pywinauto/pywinauto/wiki/UI-Automation-tools-ratings And we’re preparing beta version of “record-replay” in pywinauto soon. The only competitor with similar feature is Microsoft with WinAppDriver -> UI Recorder (but I couldn’t get it to work well so far). – Vasily Ryabov Aug 30 '18 at 06:55
  • I prefer Python/PyWinAuto as I understood it should be easy to start from scratch than other languages. Now here is my steps to perform: 1) I want to start an application, 2) Specify the window to work on, 3) Find all the controls and properties and 4) Finally get the output values from the controls my codes:from pywinauto.application import Application app = Application(backend="uia").start('calc.exe') dlg_spec = app.window(title='Calculator') dlg_spec.wrapper_object().minimize() dlg_spec.minimize() app.Properties.print_control_identifiers() – Hossain Aug 31 '18 at 19:01
  • I've posted details as an answer. If it works for you, please mark answer as accepted (it's considered polite on StackOverflow): just find and click gray check box under voting buttons. And, of course, welcome to ask more questions with tag `pywinauto` if existing answers don't cover your problem. – Vasily Ryabov Sep 03 '18 at 11:35
  • Thanks Vasily :) – Hossain Sep 05 '18 at 21:38

1 Answers1

0

Calculator is a little bit complicated case for now (yay!). Windows 10 calc.exe implementation creates another process. I can say more: its UI controls hierarchy doesn't fit into bounds of one process (really): there are few processes for one app. We have plans to detect new spawning process while starting an app, but it's NOT in pywinauto yet. But going deeper into .children() or .descendants() follows the whole hierarchy across process bounds (the only important thing: who is parent).

Current example for calc.exe looks so (see latest win10_calculator.py in the repo):

from pywinauto import Desktop, Application

app = Application(backend="uia").start('calc.exe')

dlg = Desktop(backend="uia").Calculator # window specification
dlg.type_keys('2*3=')
dlg.print_control_identifiers() # this is also window spec method

dlg.minimize()
# minimized window needs some tricks to find it and restore
Desktop(backend="uia").window(title='Calculator', visible_only=False).restore()
Vasily Ryabov
  • 9,386
  • 6
  • 25
  • 78