Published on: 01.11.2018

I found out about PyAutoGUI Python packet from Automate the Boring Stuff with Python book.

With PyAutoGUI you can automate GUI interaction on your computer.

PyAutoGUI is working on Windows, OSX and Linux, altho I have used it only on Windows.

Most GUI automation can be done just by automating mouse movements and keyboard input and PyAutoGUI supports it.

There are also functions for providing message boxes, saving the screenshot and finding an element from the image on the screen.

Personally, I have found PyAutoGUI useful, for automating some of my workflows.

To be honest, I use it for 45 minutes of work every month (I know this is not much), but I have found that if I manually have to do same interactions for 45 minutes it is really killing my soul, so I decide just to automate it.

If you want to automate web page interaction use Selenium, because with Selenium you can access elements on a web page independent of their position on the screen.

Because with PyAutoGUI you can just move the mouse to specific coordinates, that means if the resolution or layout of GUI has been changed, you need to update coordinates in your code.

Keep all coordinate in your code as constant in one place, so that you do not need to change them all over your code when change is needed.

This theoretically could be avoided if you use images as reference for finding elements on your GUI, but you will have the same problem if the appearance of the elements is changed, but then instead of changing coordinate in the code you have to change all reference images, what is more work.

My personal preference is to use hardcoded coordinated instead of images as the reference.

Using Selenium has also become popular for scraping pieces of information from web pages, but better is to use specialized framework for scraping like Scrapy, because of additional features like caching HTTP responses (quite a time saver in development).