Reputation: 107
I want to develop Python script that will open some windows-based application, then enter some data/commands simulating user using keyboard:
Of course it could return exiting code like 1 when succeed and write some logs.
I believe there is some library (probably for UI testing purpouses) but I don't know any.
I know there is Selenium but I'm afraid it's only for web browser app.
Upvotes: 2
Views: 4296
Reputation: 676
If you like Writing Scripts in Python Languages, you can use Autopythonlauncher Click Here with this Software you can make clickable Pictures with Python Scripting Codes. You can then simple write a python code to run a External Application and then You can Send any text or any Keyboard Shortcuts Macros (without focus the Windows - this means you can Send it to any Windows Applications) and it is everthing in 3d. Choose a Picture and write in the Command Editor this example code.
This Python Script Does also Work Without Autopythonlauncher. (see bottom)
#run calc
#######################
import subprocess
cmd = "C:/Windows/System32/calc.exe"
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, creationflags=0x08000000)
process.wait()
#######################
# you can send any text or Keyboard Shortcuts Combinations - pyautogui.hotkey('ctrl', 'c')
# send "5", "+", "8", "/", "2"
# send "Enter"
#######################
import pyautogui
import time
time.sleep(.500)
pyautogui.press(['5','+','8','/','2'])
pyautogui.hotkey('enter')
#######################
Look to this intro youtube video Click Here you can see what AutoPythonlauncher Software can do.
Note: If you want to test it out without AutopythonLauncher Software.
You will need to make this bat file, Run this to install the packages pyautogui. The only Contra is you can not use it (without focus the Windows)
install.bat
C:\Python27\scripts\pip.exe install pyautogui
pause
Upvotes: 0
Reputation: 2682
Why not just use AutoHotkey?
Full Script:
RunWait, Calc.exe
sleep, 500
Send, 5{+}8{/}2{Enter}
ExitApp, 1337
This script can be compiled as a standalone .Exe and run from a Python script which can retrieve it's exit code of 1337 through StdInput.
Upvotes: 1