I'm automating an application (pywinauto ver 0.6.2) in which I:
search for a record
open a dialog
make changes
click an OK button
wait for the dialog to close
when closed, search for the next record, repeat
In the 'wait for the dialog to close' step I am using:
dlg.wait_not("visible", timeout=60)
This works most of the time, but sometimes it not only doesn't detect that the dialog has closed, but it also doesn't appear to do anything at the 60 second mark.
Is there a better way to detect the close of a window?
The bug with timings is fixed in pywinauto 0.6.3. Please update it with pip install -U pywinauto. Method wait_not is also affected.
Related
I'm trying to dismiss an alert, close a window, or suppress an alert or window from opening in the first place in Selenium (with Python), and I'm stuck with an infinitely loading window.
Screenshot of window loading
I'm working with the Selenium webdriver in Python, and when I enter text into one window's text box, in certain circumstances a new window automatically pops up with an alert in it. However, the window apparently loads infinitely. I do not need to interact with the window; I'd be fine if I could just close it out immediately.
But since the page is still loading, I cannot find a way to dismiss the alert or to force close the window. It just loads forever; the only thing I've been able to do is actually click the "OK" button myself, and this needs to work without manual user input.
Anyone know how I can either dismiss this alert or force the window to close? Or maybe suppress the window from opening or suppress the alert?
Thanks!
I've tried changing the page load timeout to then close the window or dismiss the alert, but that doesn't work. I cannot switch to the window and interact with it, and I cannot use driver.switch_to.alert.dismiss() or driver.close(); my code just hangs forever. I found that if I manually minimize the window, the alert is dismissed and I could probably interact with the window then, but I can't minimize the window with code; my code won't progress while the window is loading.
(Unfortunately this cannot be reproduced without someone using a private account to log into the system.)
Is it possible to interact with a webpage loaded into a web browser (such as Chrome) without the window being active and without sending keystrokes to it? For example, suppose I have SoundCloud loaded in chrome and the chrome window minimized, but I want to create a hotkey on my computer (such as through Autohotkey) which acts as a play/pause button for the track. Would it be possible to have a Python script somehow interact with the browser to obtain that functionality without having to send it a keystroke?
The reason I'm trying to avoid having to send keystrokes is because it would require the Window to become briefly maximized and active. I can already do this in autohotkey. For example, I have an ahk script that iterates over all the windows, finds one with Soundcloud in the title, maximizes the window if it is minimized, sends the spacebar keystroke (which acts as play/pause on Soundcloud), and then minimizes the Window again if it was minimized to begin with.
This has the undesirable effect of making the Window flash briefly if it was minimized, or if virtual desktops are used, all the Windows flash if the Chrome window with Soundcloud is located on another virtual desktop other than the active one.
Ideally I could just write some program that runs silently in the background to send some kind of the request to the site that has the same effect as pressing the play/pause button without having to use the janky keystroke method I suggested above. But I am not sure if this is possible. What is actually happening when I click the play/pause button on Soundcloud, and is there some way write a program to get Chrome to do that without using keystrokes?
Any suggestions? I would prefer to do this without any browser plugins if possible.
I have a code, and I want to be able to clear the run window after certain actions are performed, however I haven't been able to find a way to clear it aside from clearing it yourself using the 'clear all' button(PyCharm btw). Is it possible to do that?
It seems that you can't clear the pycharm terminal without the clear button, however running it in cmd, the os.system('cls') or os.system('clear') works and will clear the screen.
You can't clear the pycharm window without the clear all button, but the os.system('clear') will clear the window if you run it in cmd instead so use that instead..
I'm creating an application in which users can select a specific part of the screen to screenshot, which will then get processed. The (naive) way that I'm doing this currently is using the pyautogui library to simulate the windows shortcut for that:
def take_screenshot():
time.sleep(1)
# Windows hotkey for selective manual screenshot
pyautogui.hotkey('win', 'shift', 's')
time.sleep(8)
# return retrieved screenshot from clipboard
return ImageGrab.grabclipboard()
This is obviously a very hacky solution, as i am just halting the program for some amount of time until the use has selected a specific area using the screenshot. But i'm wondering is what the best way is to handle this? I want to wait until the user is done taking a screenshot to process it, so i was thinking there is a way to listen to windows events to know whether a screenshot is still being taken?
I'm currently making a lil' launcher for PortableMu while in an internship.
We (company and I) modeled a special mode for the Mu-Editor and we are shipping it with PortableMu so that users don't need to install Mu and/or Python to use it.
The problem of PortableMu for Windows is, that you start it with a .bat and this doesnt give you any feedback.
You click, you wait ~1-2min and maybe Mu-Editor will popup.
This is not very userfriendly.
So my duty is to create a launcher.
My launcher is a simple thing: Only lil "welcome" a picture and a button to start PortableMu. It works on my private windows10.
Now I want to add in randomly picked messages for simulating "loading" which shall stop when the Mu-Editor pops up. Simply to bridge the time
Is there a method to catch when this happens?
Alas:
Can Python catch the moment when Windows opens the task/process for Mu-Editor?
If, how?
use the tasklist
subprocess.Popen('tasklist').comunicate()[0] will return all the tasks currently happening in windows, simply do this every minute or so and check for your task. There are ways to make this pass without a command window popping up, here's one that i use often
command =subprocess.Popen(["ping","-n","1","-w","100", str(ip)], stdout=subprocess.PIPE, shell=False, creationflags = 0x08000000)
reply = str(command.communicate()[0])