Use python to execute a windows program
Doran, Harold
HDoran at air.org
Fri Sep 11 12:46:16 EDT 2009
I am working with this now. I'm toying with the examples to test out a
few things and learn how this works. I've made some modifications such
that I have the following working (below). This does nothing more than
open a program.
I have commented out the portion
#app.AM.MenuSelect("File->Open Database")
When it is uncommented, the program fails. However, when I tinker with
this MenuSelect() for, say, Notepad, this presents no problem and
behaves as expected. For example, the following works with notepad:
app.Notepad.MenuSelect("Help->Help Topics")
At the risk of sounding too silly, how do I know what to place after
app.??.MenuSelect? I've tried this with a few programs and the name I
use in place of ?? Doesn't seem to work.
import time
import sys
try:
from pywinauto import application
except ImportError:
import os.path
pywinauto_path = os.path.abspath(__file__)
pywinauto_path = os.path.split(os.path.split(pywinauto_path)[0])[0]
import sys
sys.path.append(pywinauto_path)
from pywinauto import application
def AM():
app = application.Application()
try:
app.start_( # connect_(path =
ur"C:\Program Files\American Institutes for
Research\AMBeta\AM.exe")
except application.ProcessNotFoundError:
print "You must first start Windows Media "\
"Player before running this script"
sys.exit()
#app.AM.MenuSelect("File->Open Database")
def Main():
start = time.time()
AM()
if __name__ == "__main__":
Main()
> -----Original Message-----
> From: simon.brunning at gmail.com
> [mailto:simon.brunning at gmail.com] On Behalf Of Simon Brunning
> Sent: Friday, September 11, 2009 11:02 AM
> To: Doran, Harold
> Cc: python-list at python.org
> Subject: Re: Use python to execute a windows program
>
> 2009/9/11 Doran, Harold <HDoran at air.org>:
> > The way we do this now is a person sits in front of their
> machine and
> > proceeds as follows:
> >
> > 1) Open windows program
> > 2) Click file -> open which opens a dialog box
> > 3) Locate the file (which is a text file) click on it and let the
> > program run.
>
> It might very well be possible, depending upon how the
> program you want to automate has been written.
>
> First, make sure, absolutely sure, that's there's no "proper"
> automation option available - a command line version, COM
> automation, that kind of thing. These approaches are very
> much easier than GUI automation.
>
> If none of these options are available,
> <http://pywinauto.openqa.org/> is probably what you need.
>
> --
> Cheers,
> Simon B.
>
More information about the Python-list
mailing list