DEV Community

Raghwendra Sonu
Raghwendra Sonu

Posted on

Windows Desktop Automation with pyWinAuto

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.

Installation- > pip install pywinauto

To use this tool, you need to get attributes of your application. For this purpose you can use PyInspect tool. Clone the below repository:

and run python from command prompt.

Alt Text

You can inspect the properties of all the elements using this tool.

Later, you need to use these attributes for automation using pyWinAuto.

I will write a python file that will do following stuffs:

  1. launch Notepad
  2. type 99999 in the notepad
  3. Click on Edit -> replace
  4. Click on Cancel button on the Replace Dialog box.
  5. Again it will enter "Hi from Python...." text in the notepad
  6. It will navigate to File-> Save menu
  7. Save the file with name "Test"

Here is the pyWinAuto code for this use case:

from pywinauto import application
app.window(best_match='Untitled - Notepad').type_keys('99999')
app.UntitledNotepad.menu_select("Edit -> Replace")
app.UntitledNotepad.Edit.type_keys("Hi from Python.....")
app.window(title='Test - Notepad').wait('ready', timeout=10)
except TimeoutError as e:
raise e

Alt Text

Here is the execution video.

Hope this was helpful. For more details go through pyWinAuto documentation:

Top comments (0)