Document Actions

Introduction to pywinauto

Filed Under:

by Mark McMahon

He's a localization software engineer, uses python for interfacing with legacy applications, for tools, and automating stuff. Python is unfortunately not a standard in his company.

What is pywinauto?

It automates clicking in Windows. E.g. open up Microsoft Paint, create a new file, paint something. Hard to write tests for.

If you set the delays between commands too short, the right window may not have come up yet so you get an error. Be aware of that.

It was first written in C to analyze localized dialog boxes for GUI bugs (1998). Then moved to C++ (2000), then python (2005). Conversion to C++ took two years, to python two or three months. :)

Example:

from pywinauto.application import Application

app = Application.Start("Notepad")

app.Notepad.Edit

app.Notepad.Edit.TypeKeys("Hello World")

WinSpy or Winspector help you to figure out which classes to use, e.g.

canvas = app.untitledPaint.Afx1000000008

Pywinauto is all dynamic:

  • no dialog declaration needed
  • fuzzy matching of titles (resistance to software changes)

Easy to understand.

It could use a script recorder, integration with test tools and a merciless refactoring.

Microsoft Office is done very differently, uses other controls. You can't use pywinauto for that.

See Mark's blog