Im trying to communicate with a windows application with python. Need to fill in text fields and retrieve results (which are also displayed in text fields).
Currently using PywinAuto, works perfectly but its too slow for my purpose. Filling in 6 textfields and pressing two buttons takes 2 to 3 seconds... Im looking for a way to speed this up.
What is the fastest way to control and retrieve data from a windows application, that is feasible for a beginner in Python?
Thanks in advance.
This is very difficult. PywinAuto is one of the best ways to handle this kind of problem, but you have to be very careful about which Windows application you are working with. This is because not every Windows application will "publish" it's controls in a reliable way for you to automate. This is particularly true of Mozilla Firefox. However, the Microsoft Office suite does consistently publish just about every control and button on each of its interfaces that I have ever seen. Thus, the real problem is not with PywinAuto, or even with Windows, it is with whoever wrote the application you are trying to automate and whether or not they reliably publish the interfaces you were trying to control.
The other question you have to ask yourself is how you are populating the text fields and what is actually taking the time. Filling in fields and buttons should take a fraction of a second if they are independently workable. Otherwise, there is probably something else going on that you should investigate.
Good luck. This is a really tough problem.
I have been using pywinauto for 1.5 years. And I have tried lots of different tools for UI automation. You know what, pywinauto not the slowest among them.
Ofcource some actions can take a long tome (seconds), but as a rule it is a high weith actions, such as count children, etc.
Please be sure you do not call findwindows method when it is not realy need.
Related
I'll try to be as concise as possible:
Quite some time ago, I started using arduinos and other microcontrollers as custom MIDI devices for my PC.
But now, since I'm into filmmaking, I wanted to create a grading panel for use in Blackmagic's DaVinci Resolve. What i want exactly is to read signals from knobs and slider with a microcontroller and send the data to my PC so that Resolve can use it to apply different adjustments.
Unfortunately, since there are many different adjustments, there are no keyboard shortcuts for them, so I can't just emulate them with the microcontroller.
I have tried to use Cheat Engine to see if those adjustments values where stored somewhere in memory, but I can't seem to find them.
Resolve does have a Python and Lua API, but they're extremely limited and don't offer ANY control over color adjustements anyway.
I know that a few people that had my same idea used another software that mapped MIDI input to mouse movement, but I hate that solution, since the UI not only must be visible at all time, but you also can't change UI elements without needing to 're-calibrate' the mapping software.
To clarify: I'm not asking for code, I'm asking for 'directions'. How can I control a 3rd party software with custom made hardware? (I'm on Windows 10 btw)
I'm working on a school project which I would like to showcase in a web browser or application.
I would like the user to control the work with a mouse or keyboard. I want to show a unique image based on where the curser is over a visible grid. An additional feature is the ability to switch to a different "stack" of images upon user input from the scroll wheel or in a dialog.
I have a beginner-intermediate understanding of Python.
Theoretically, I could write this using Sage, but I would like the feedback to be instant - a change shouldn't require a new calculation, just show a new image.
Additionally, I would like to create a feature which takes the user on a "tour" based on information attached to an image.
My first thought was to use an online website builder (Webflow), though an opportunity to learn a new language or expand upon my knowledge of Python is my first choice.
What language is best suited for this?
This is possible in Python, as nearly everything is (Python is a Genral Purpose Language), so you could certainly implement this in Python.
The best language for this, however,IMO, would be JavaScript.
Python will almost certainly get in your way or at least hinder you slightly in comparison.
An 'online website builder' is not likely to provide you with the required amount to control needed to implement you project - most of these are painfully simplistic drag-and-drog tools where any real control only comes from adding your own CSS/HTML/JS anyways.
JS is an incredibly useful language and also very well suited for nearly all web/browser projects, so use this opportunity to learn it !
Further, React Native can let you use JS for mobile apps too, if that's what you meant by 'applications' or you could simply keep it a web app.
PS. This may also be possible with HTML5, which is perhaps simpler and easier to learn, but I'm no a web dev so that will have to be confirmed by someone else.
I am sure, though, that this is very efficiently doable in JS.
I have something in my clipboard, and I'd like to run a python script that invokes CTRL+V as if it was pressed on the keyboard, and pastes the clipboard's content to the current focused window (say chrome). Any idea how to do that?
You have an X-Y problem.
What you want to accomplish is programmatically take data from one program (where you hit cntrl-V) and place it into another arbitrary program (chrome).
There are two ways to do that:
First
You can either set the programs up to have a data exchange mechanism such as a system pipe, or a network connection. This requires some API for data exchange to be already included in the program or access to the source so you might add one. There are very specific channels for cross program data exchange and you wont do well to try to circumvent them. Program A cant just say
get_program_b().get_text_box().add(clip_board);
That would be a violation of Process Isolaton and an OS like windows is written expressly to make it impossible. Some programs are designed to take input from other programs.
popen.open('mysql -e "ISNERT INTO table (a) VALUES ('4')")
Chrome is not one of those programs, chrome avoids allowing programs from doing this because it would be a target for programs to do things like, get the saved password or credit card data out of chrome. Or use save password to login to someone account and buy things in someone elses name.
Second
You could try to spoof user input and input the data exactly like a user would so chrome wont know the difference. But spoofing a user is hard to do and intentionally so because it prevents malicious scripts from taking control of a computer and doing bad things. The makers of windows are accutely aware that spoofing input is a method to circumvent allowed data exchange channels. So the makers of windows made it hard to do. You need to have access to a lot of system assets that most programs wont be given. At a minimum a program has to run as admin on windows to accomplish this, then there are libs that will let you do it. Even then Im willing to bet there are easier way to get the job done. On a machine where you have access to anything and everything it is possible. If you don't have admin access, it should be downright impossible without knowing some unpatched exploit in the system.
Therefore
What you are trying to do goes against what the computer was designed to let you do. If we had more information on what you want to accomplish maybe some of the wonderful people here could help. Getting to the end result you want shouldnt be that hard. But you way of doing it is like trying to run across the ocean, when you just need a boat. As it is my answer is -- dont do it, that's not how windows was designed to work.
I know about tampermonkey/greasemonkey and have used it a fair bit, but now my task is to write a program that runs in the background and automates mundane tasks (clicking buttons, typing into input fields etc.) on a specific webpage. Running a browser in the background takes too much RAM and processing power, so I'm looking for an alternative.
So far I've found selenium, but after a bit of research it looks like that it requires to have a browser open at all times as well (or maybe not? the documentation isn't that good). I thought about python scripts too, but I don't have any experience with those nor have I any idea if they can handle anything that's not basic html. If they can, does anyone know of a good tutorial for python scripts? I have used that language a few years ago, so I shouldn't really have a problem with python itself.
If python scripts aren't ideal either, is there a (preferably somewhat simple) way I could achieve what I want?
It depends on whether you want a script that interacts with a web UI, or a script that automates web requests. Do you really need to click buttons and type into input fields? Presumably, the data from those buttons and input fields is eventually sent to a web server. You could skip the entire UI and just make the requests directly. You don't need a browser for that and python is fine for doing these types of things (you don't even need selenium, you can just use requests)
On the other hand, if you're trying to test out the UI of a web page, or you actually need to interact with the web UI for some other reason, then yeah, you'll need an application (like a web browser) that's capable of rendering the UI so you can interact with it.
I'm contemplating using python for some functional testing of flash ad-units for work. Currently, we have an ad (in flash) that has N locations (can be defined as x,y) that need to be 'clicked'. I'd like to use python, but I know Java will do this.
I also considered Jython + Sikuli, but wanted to know if there is a python only library or tool to do this. I'd prefer to not run Jython + Sikuli if there is a native python option.
TIA.
#user1929959 From the pyswftools page, "At the moment, the library can be used in Python applications (including WebBased applications) to generate Flash animations on the fly.". And from the bottle-flash page, "This plugin enables flash messages in bottle.". Neither help me, unless I'm overlooking something ...
There are a number of ways I've seen around the net, but most seem to involve exposing Flash through JS and then using the JS interface, which is a bit of a problem if you are trying to test things that you don't have dev access to, or need to be in a prod-like state for your tests. Of course, even if you do that, you aren't really simulating user interaction, since you are working through an API.
If you can reliably model your Flash components with fixed pixel positions relative to the page element the Flash component is running in, you should be able to use Selenium Webdriver to position the mouse cursor and send click commands without actually cracking Flash itself. I'm not 100% sure that would work, but it seems at least worth a shot. Validation will be a bit trickier, but I think you should be able to do it with some form of image comparison. A few of the Flash automators I saw are actually using image processing under the hood to control both input and output, so it seems like a legitimate way to interact with it.