GUI automation with Python x Windows App Driver

[Introduction]

Originally it seems that the plan was to have WinActor used in the field, I had a contract for a while, but I couldn't recover the investment, so I cut the entire budget of RPA including WinActor. As a result, we decided to proceed with RPA with the necessary cost of 0 yen. This time, I will write about the struggle to realize the automatic operation of GUI.

[Introduction]

There are various types of automation of GUI operations. The first thing I arrived at was image authentication using pyautogui + keyboard / mouse operation. This will definitely operate the keyboard and mouse, but I'm not sure if they really operate the screen.

If you add image authentication to it, the accuracy will increase considerably. However, this also has its drawbacks. ・ Slow because the operation is to search for the specified image on the screen display. ・ It does not respond if the background image of the desktop is changed. ・ The operation changes with one image to be searched.

I searched for something more stable and found it. It's "UI Automation" Rejected for the following reasons ・ I don't like coding personally ・ The amount of information is small (I personally felt that ...)

I gathered various information from there and arrived at it. "Windows App Driver" (WAD because it is long) The following are the reasons for adoption -Coding looks similar to Selenium └ Anyone can use it if they remember Selenium. And vice versa ・ The information is relatively new, and you can easily find it if you look it up.

* The basic mechanism of UI Automation and WAD

It's similar to VB.net or JQuery It is a type that supplements the target and operates by specifying the ID of the operation action and other attributes.

[Main subject]

Basically, it will work if you do the contents written in the following URL. https://arakan-pgm-ai.hatenablog.com/entry/2019/08/19/000000

The contents I devised are as follows

① Operating environment

First, you need to give the execution environment "Developer Mode" permissions. Therefore, the option of choosing a personal computer as the execution environment was quickly eliminated.

I chose to use Windows 10 in a virtual environment (If you can't prepare a virtual environment, you can use a PC that has been withdrawn as a substitute for a PC.)

Another purpose is to prevent humans from competing with resources such as clipboards, mice, and keyboards. It also makes maintenance easier.

If there are 10 workers, it may be necessary to install it on 10 PCs. If multiple workers gather, some people may not follow the precautions. Even if there is only one worker, there are various things such as changing the person in charge. We take the method of creating and operating an environment that workers cannot touch.

How to run an automated program? This is easiest to use with a task scheduler or something. There are various measures around here, so I will come back later.

② How to prevent accidentally closing the WAD screen

As automation using WAD becomes more widespread, other programmers will start using this environment. Then, even those who do not understand well will start using it by imitating the appearance. When that happened, I closed the black screen ... It ’s something that you do   In that case, even if you set the startup with the task scheduler etc. It doesn't move because WAD is stopped.

The simplest countermeasure would be to start it so that the black screen is not shown. The following code should be placed in Shell: startup

wad.vbs


dim ws
Set ws = CreateObject("Wscript.Shell") 
ws.Run """C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe""", 0

③ When the application to be operated is over the remote screen

Since it cannot be operated, let's install the application to be operated locally. As you can see from the GUI research tool, when trying to operate through VNC or Xen You can only get information about the campus part of the VNC or Xen screen.

④ Improvement of input speed

Input the character string to be input to the clipboard using pyperclip Let's paste by sending Ctrl + V to the text box. You can use the standard input mechanism, but It behaves like hitting the keyboard, so when entering long sentences The operating speed will be slower.

⑤ When the application to be operated is batch started & started

It ’s a premise, The code below works like launching the calculator and supplementing the calculator's app.

desired_caps["app"] = "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App"

for that reason You cannot supplement the app by specifying the batch path in desired_caps ["app"].

subprocess.Popen(['start',Batch shortcut PATH], shell=True)
#Certainly, explorer should have been good as well as start.

-Change the following part of the Python code

desired_caps["app"] = "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App"
 ↓
desired_caps["app"] = "Root"

This complements the desktop itself.

If the above two conditions are met Is the application with the wind title "●●●" running on the desktop? You will be able to confirm that. So ● Wait for a second, and if you can't find it, you can make an error / start, and you can continue working.

⑥ How to operate the dialog

You can also operate after checking the attribute value in the same way as a text box etc. Some are quite complicated.

As a countermeasure, After checking the wind title This can be easily achieved by combining it with the keyboard operation of pyautogui.

I think that most things can be done by doing this much. Next time, let's summarize the area around automatic operation of the WEB.

Recommended Posts

GUI automation with Python x Windows App Driver
Python starting with Windows 7
Summary of tools for operating Windows GUI with Python
PIL with Python on Windows 8 (for Google App Engine)
Python with VS Code (Windows 10)
x86 compiler self-made with python
Run python with PyCharm (Windows)
[GUI with Python] PyQt5-Layout management-
[GUI with Python] PyQt5 -Preparation-
Time synchronization (Windows) with Python
[GUI with Python] PyQt5 -Paint-
Build Python3 for Windows 10 on ARM with Visual Studio 2019 (x86) on Windows 10 on ARM
Face detection with YOLO Face (Windows10, Python3.6)
Install Python 2.7.9 and Python 3.4.x with pip.
[Automation] Extract Outlook appointments with Python
[Automation with python! ] Part 1: Setting file
[GUI with Python] PyQt5 -Widget II-
Let's make a GUI with python.
[Automation] Send Outlook email with Python
[GUI with Python] PyQt5-The first step-
Easy GUI app with Tkinter Text
[GUI with Python] PyQt5-Drag and drop-
Build mlpy with python3.3 (64bit) (windows 64bit)
Use Windows 10 speech synthesis with Python
[Automation with python! ] Part 2: File operation
[GUI with Python] PyQt5 -Custom Widget-
Getting started with Python 3.8 on Windows
[Python] Creating multiple windows with Tkinter
[Python Windows] pip install with Python version
Run servo with Python on ESP32 (Windows)
[Automation] Manipulate mouse and keyboard with Python
Uncle SES modernizes VBA app with Python
Create a simple GUI app in Python
Create a GUI app with Python's Tkinter
Building a Python 3.6 environment with Windows + PowerShell
Shared screen screenshot exe app with python
Daemonize a Python web app with Supervisor
Develop Windows apps with Python 3 + Tkinter (Preparation)
Use without installing python 2.x on Windows
Easy web app with Python + Flask + Heroku
[Automation] Read a Word document with Python
Create an English word app with python
Join an online judge with Python 3.x
Data integration from Python app on Windows to Amazon Redshift with ODBC
Happy GUI construction with electron and python
Make a desktop app with Python with Electron
Run (legacy) Windows apps with Windows Application Driver
Installing PIL with Python 3.x on macOS
Light image processing with Python x OpenCV
[Automation] Read mail (msg file) with Python
[Blender x Python] Let's get started with Blender Python !!
Othello app (iOS app) made with Python (Kivy)
Easy Python data analysis environment construction with Windows10 Pro x VS Code x Docker
Project cannot be created with Python3.5 (Windows) + django1.7.1
I made a GUI application with Python + PyQt5
Vienna with Python + Flask web app on Jenkins
GUI image cropping tool made with Python + Tkinter
[Automation] Extract the table in PDF with Python
Python (Windows 10) Virtual Environment / Package with VS Code
Install OpenCV 4.0 and Python 3.7 on Windows 10 with Anaconda
You can easily create a GUI with Python