I'm researching about pywinauto and pywin32. I want to write a script to automate downloading a file in Firefox. When downloading a file in Firefox, it will show a popup to ask you to open or save the file, and you have to choose an option and follow steps. How can I locate controls (items) on this popup by using pywinauto or pywin32?
You should investigate selenium ide. You can use that and Python to automate much of firefox. The forums there should point you in the right direction. This downloading issue is a persistent one.
good luck!
pywinauto installation has an example (SaveFromFirefox.py) related to this:
http://pywinauto.googlecode.com/hg/pywinauto/docs/getting_started.html
You might check out Project SIKULI from MIT. With it you can write macros by taking screenshots. The project screenshots make the entire process look dead easy. It's Python-based, too, so it may be the write tool for the job.
Also, if you have control of the computer in question, you may be able to check the box in the download popup that says "Do this every time" (or whatever the exact wording is). Perhaps that will be enough to make the job simpler?
For latest Firefox version you can use pywinauto 0.5.x (just download and run python setup.py install or run pip install pywinauto). SaveFromFirefox.py was adapted for Win7.
Useful tips:
app.Dialog.PrintControlIdentifiers() will print all possible access names for the controls on a dialog.
SWAPY is a GUI helper for the controls hierarchy inspection and code generation for pywinauto.
app.Dialog.ControlName.WrapperObject(). ... will give you the most useful list of methods available for the control. In a production code the WrapperObject() call can be omitted.
Related
Whats the best Python library to automate an external program
We have accounting software where we need to upload many files into for a particular reason. To do this we search for the relevant menu item right click it and then import. This is time consuming. It would be useful to be able to automate this. Ive looked at pyautogui but it needs the screen to be active and the user cant do anything else on their machine while it is running.
Of course ideally I would like to use the accounting software's API (if there is one) or find out if the upload is running a stored procedure at the back end taking the filepath as a parameter and then calling this procedure myself.
In the absence of those would anyone know if there is a way to automate this in Python without the limitations above or if not in Python what other language would be good for this?
Many thanks
I haven't done such thing. So I do not have proof of concept. But
You have at least 2 options, more or less complicated:
install virtualbox/vmware, and create virtual operating system (windows or Linux) on it. Then run your pyautogui script in this virtual operating system. You operating system is available in window-like container - so you can minimize this window with running script, and you system where you can interact as a user. (long tutorial: https://www.virtualbox.org/manual/ch01.html)
If you are Linux user, then you may be familiar with virtual screen. I think many people are using this virtual screen with automating web testing in sellenium (How do I run Selenium in Xvfb?). So probably, I say probably, there is chance to run pyautogui in virtual screen: How to attach pyautogui to the virtual display? - this is similar, but not answered question.
I'm looking for an equivalent Python library that will work when I run my script on Raspberry Pi. I'm under the impression that pywinauto only works on windows machine.
I want to control some inputs to a GUI launched by my script, using my script. Apart from pywinauto I have no idea how to do this. I thought about using command line to control the software directly, but if there is a simpler way I would really appreciate knowing about it.
Thanks for your time.
ATSPI is an Linux accessibility technology to obtain GUI text/rectangle properties programmatically. See how to find and run ATSPI registry daemon and how to enable ATSPI for the most popular types of GUI apps. Usually it's
$ /usr/libexec/at-spi-registryd &
There is a Python bindings for ATSPI. See this answer for details:
How to install pyatspi?
The pyatspi package has too many dependencies like pygobject etc. It also requires some compilation during installation steps. We think this is not user friendly so we decided to use libatspi.so directly (without any dependencies). This work status can be tracked here: https://github.com/pywinauto/pywinauto/pull/449
There is no exact deadline for pywinauto 0.7.0 with this feature (it's a hobby project), but I would say this summer sounds realistic.
I have written a program. I don't know if it is important how it is written but you can find it here: http://pastebin.com/Z3ZvVPV8 Basically, it asks you to assign values to variables and will perform calculations depending on what variables you chose, and prints the answer.
I would like to know how I can make the program run in a window other than cmd (I am using Windows Vista 32bit). I don't need much at all in terms of GUI, just a window that is a bit more user friendly/easier to look at when they are using the program.
EDIT: To those suggesting using IDLE, while that would work for me, if others want to use the program they would have to download it, so I was hoping for a way for that not to happen.
Python comes with a sort of default GUI package TkInter you can use it.
Also there is a lot of other GUI packages available.
The Python standard library offers a lot of ways to implemt simple (but also rather complex) GUIs. I'd like to point you at the documentation of TK (tool kit for graphical interfaces) http://docs.python.org/library/tk.html where you will find also some useful example of use.
Py2Exe is a viable option if you really don't need a gui. This will make it run and look like a command prompt, but it will be an .exe file. Here is a quick quote from thier page: "py2exe is a Python Distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation."
Another alternative is to get Portable Python. Here is a quote from thier webpage: "Portable Python is a Python® programming language preconfigured to run directly from any USB storage device, enabling you to have, at any time, a portable programming environment. Just download it, extract to your portable storage device or hard drive and in 10 minutes you are ready to create your next Python® application." After packaging the portable python and your .py or .pyc file then create a .bat file that runs the portable python "Python-Portable.exe" with the correct command line parameters for loading your script. Be sure to use relative paths in the batch file in case they are running it from a flash drive, or something other than the same location as you.
NOTE: This is really not a good way to do this as thier download page states: "Installed size: based on selected packages, between 49MB and 480MB". Also be sure to read the the current Python Software Foundation License, as that is what Portable Python is released under, and it may or may not be legal to package it in a closed source project. I haven't really looked at the license myself to be able to tell you. If you are releasing it as open source, then there would not be an issue though. As a quick side note, if you need that .bat file to be a .exe file then you can use a .bat to .exe converter battoexe.com is one. This is really going the long way about doing the whole thing, but it is an option.
Sources:
Working with Python on and off for 7 years now, a lot that using a portable version on a flash drive, and also dealing with Batch files much longer.
So, I've been searching the topic for quite a while, but I am unable to find out whether it is possible or not. I suspect not, but I need to be sure.
What I'm doing:
I am building a fancy web app that uses xml, xsl and javascript. However, I need to do some transformation to a text file to convert it into a proper xml file. To do this, I use a python script.
What I need:
I am working to make as easy as possible the use of the app, but this gets kind of destroyed when the user has to execute a terminal script before anything. I need a graphical IDE for python, but I just don't have time to learn how to make one, and I would love that the entire app would work within the same web environment, much more intuitive for the user. Then, a really easy way to do that would be to use Firefox as the IDE, for example choosing the file to be transformed through it, and launching from there the python script.
What I require:
I need compatibility only with Firefox. But of course any system capable to install Python and Firefox should work as well. The user would happily install both programs, as long as they have interest in the app.
What I don't know:
Is that possible, to execute an external python script? If not, for security reasons I imagine, is there any way for the user to allow it? Maybe through the installation of a plugin?
maybe http://mozex.mozdev.org/ is what I am looking for?
Thanks!
Gerard
Yes, It is possible to execute an external python script. You can use a simpleServer (example) that receives a (Ajax) request from your page and calls a subprocess or os.startfile to launch the script. In fact, you can call the function itself from within the server and return the result (e.g. as json) to the page and use your javascript to handle it.
If you're after actually using python in firefox, rather than having the server side written in python (although the webserver can of course be running locally), I would guess pythonext (used to be pyxpcomext) is what you need.
The problem I have is that I have this Python script to launch a application. After the application is launched (the GUI is shown on screen), I want to make it de-activated. It can be done manually by activating another window, or minimizing this app, or pressing the Show Desktop key for WindowsXP.
So is there any way that I can do this by Python? Core or 3rd party library would be all ok.
Thanks!
Take a look at SendKeys. It is in the pypi, so you can install it via easy_install.
You can use pywin32 to send a minimize event.
I've used AutoIt (via it's COM interface) a lot of times