There are famous places such as Selenium on the Web, but it seems that there is no de facto tool for operating the GUI of Windows yet.
In reality, there are many options, so I will summarize them here.
ahk
AutoHotkey wrapper for Python.
Below is a sample from the above PyPI.
from ahk import AHK
from ahk.window import Window
ahk = AHK()
win = ahk.active_window # Get the active window
win = ahk.win_get(title='Untitled - Notepad') # by title
win = list(ahk.windows()) # list of all windows
win = Window(ahk, ahk_id='0xabc123') # by ahk_id
win = Window.from_mouse_position(ahk) # the window under the mouse cursor
win = Window.from_pid('20366') # by process ID
You can operate by specifying the target with the window title or id.
PyAutoIt
This is a wrapper for AutoIt for Python.
You can operate it in a similar way to AutoHotKey. (* AutoHotKey itself is a tool originally separated from AutoIt)
autoit
To be honest, I'm not sure if it's related to AutoIt, but it seems that I'm doing my best to implement it on my own.
SikuliX
I think SikuliX is rather famous. It comes with an IDE and you can write code by Sikuli alone, but there is also a pattern that you can load and use as a Python module.
pynput
moses-palmer/pynput: Sends virtual input commands
It is a tool that can automate mouse operation and keyboard operation, and it seems that it is not possible to acquire Elements on the screen.
pyautogui
Mouse operation and keyboard operation can be automated here as well, but multi-platform = Windows, Mac, Linux can be operated.
Pywinauto
Compared to other modules of the same type, it has a lively impression due to the large number of commits.
The official sample is below.
from pywinauto import Desktop, Application
Application().start('explorer.exe "C:\\Program Files"')
# connect to another process spawned by explorer.exe
# Note: make sure the script is running as Administrator!
app = Application(backend="uia").connect(path="explorer.exe", title="Program Files")
app.ProgramFiles.set_focus()
common_files = app.ProgramFiles.ItemsView.get_item('Common Files')
common_files.right_click_input()
app.ContextMenu.Properties.invoke()
# this dialog is open in another process (Desktop object doesn't rely on any process id)
Properties = Desktop(backend='uia').Common_Files_Properties
Properties.print_control_identifiers()
Properties.Cancel.click()
Properties.wait_not('visible') # make sure the dialog is closed
The parts such as ProgramFiles and ItemsView are highly readable and feel good.
WinAppDriver
microsoft/WinAppDriver: Windows Application Driver
It is a tool made by Microsoft that can operate the GUI of Windows like Selenium.
Even if you look at the sample code, you can see the "Selenium-likeness". It is the operation of the Windows calculator.
def test_combination(self):
self.driver.find_element_by_name("Seven").click()
self.driver.find_element_by_name("Multiply by").click()
self.driver.find_element_by_name("Nine").click()
self.driver.find_element_by_name("Plus").click()
self.driver.find_element_by_name("One").click()
self.driver.find_element_by_name("Equals").click()
self.driver.find_element_by_name("Divide by").click()
self.driver.find_element_by_name("Eight").click()
self.driver.find_element_by_name("Equals").click()
self.assertEqual(self.getresults(),"8")
However, the operation in the Japanese environment is not so good, and it is difficult to solve it. ..
Maybe it's not good enough to see Pat ...? I thought, but I listed it just in case
Recommended Posts