2

I want to develop Python script that will open some windows-based application, then enter some data/commands simulating user using keyboard:

  • Run MS Calculator then: "5", "+", "8", "/", "2", "Enter" and that's it
  • Run MS Notepad then: "Hello world!", "Ctrl+s", "My file", "Enter", "Alt+F4"

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.

5
  • 2
    You can try AutoHotKey and its implementation in Python Commented Nov 5, 2017 at 14:19
  • To test Windows Apps the best solution is Winium Commented Nov 6, 2017 at 5:08
  • @Andersson I tried pyahk but looks like the project is discontinued. I have difficulties to find proper .dll neccessary to work with the pyahk installed via pip. Do you have any solution for this? Commented Nov 9, 2017 at 19:18
  • Try it with Python 2.7. There should be no problems with installation Commented Nov 9, 2017 at 19:54
  • @Andersson That's what I did. Problem is with AHK (or its libraries) not python or pyahk itself. Commented Nov 9, 2017 at 19:57

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.