Take the 2-minute tour ×

I try to automatically download a file by clicking on a link on the webpage. After clicking on the link, I get the 'File Download' Window dialog with 'Open', 'Save' and 'Cancel' buttons. I would like to click the Save button.

I use watsup library in the following way:

from watsup.winGuiAuto import *

optDialog = findTopWindow(wantedText="File Download")

SaveButton = findControl(optDialog,wantedClass="Button", wantedText="Save")


For some reason it does not work. The interesting thing is that exactly the same code works perfectly to click on 'Cancel' button, however it refuses to work with 'Save' or 'Open'.

Anybody knows what I should do?

Thank you very much, Sasha

share|improve this question
Is it really a simple button, or a submit button? –  Alan Haggai Alavi May 24 '09 at 20:13
It is a regular windows 'File Download' window with a regular Open, Save and Cancel buttons. It is the regular window which is opened each time you download any file from the web. –  Sasha May 25 '09 at 19:06

4 Answers 4


It is highly likely that the file dialog you refer to (the Security Warning file download dialog) will NOT respond to windows messages in this manner, for security reasons. The dialog is specifically designed to respond only to a user physically clicking on the OK button with his mouse. I think you will find that the Run button will not work this way either.

share|improve this answer

Try this:

from watsup.winGuiAuto import *
optDialog = findTopWindow(wantedText="File Download")
SaveButton = findControl(optDialog, wantedClass="Button", wantedText="Submit")
share|improve this answer
Since the text of the button is Save, I do not think this will work. –  Alan Haggai Alavi May 25 '09 at 1:34
Except that "Save" doesn't work either. Do you know why? –  Robert Harvey May 25 '09 at 1:57
It does not work. In fact, the command SaveButton = findControl(optDialog,wantedClass="Button", wantedText="Save") actually works. I can tell it by win32gui.GetWindowText(SaveButton) which returns '&Save', such that I know for sure that the button is recognized. However, the command clickButton(SaveButton) applied afterwards does not work... –  Sasha May 25 '09 at 19:15
Does the button you are clicking require the focus before SaveButton will work? Is the button grayed out (disabled) at the moment SaveButton executes, because the dialog is waiting for some input to validate? –  Robert Harvey May 25 '09 at 19:25
No, it is not disabled. I can easily press on it with a mouse. I don't know if it requires focus. Suppose it does, how do I focus on it? –  Sasha May 25 '09 at 19:33


The code at this link is supposed to work. It uses ctypes instead of watsup.winGuiAuto, and relies on win32 calls. Here is the code:

from ctypes import *
user32 = windll.user32

EnumWindowsProc = WINFUNCTYPE(c_int, c_int, c_int)

def GetHandles(title, parent=None):
'Returns handles to windows with matching titles'
hwnds = []
def EnumCB(hwnd, lparam, match=title.lower(), hwnds=hwnds):
title = c_buffer(' ' * 256)
user32.GetWindowTextA(hwnd, title, 255)
if title.value.lower() == match:

if parent is not None:
user32.EnumChildWindows(parent, EnumWindowsProc(EnumCB), 0)
user32.EnumWindows(EnumWindowsProc(EnumCB), 0)
return hwnds

Here's an example of calling it to click the Ok button on any window that has the title "Downloads properties" (most likely there are 0 or 1 such windows):

for handle in GetHandles('Downloads properties'):
for childHandle in GetHandles('ok', handle):
user32.SendMessageA(childHandle, 0x00F5, 0, 0) # 0x00F5 = BM_CLICK
share|improve this answer
Nop, the same symptom: Save button does not work, Cancel works perfectly. Here is the example (it is not the same page that I need, but it reproduces the same problem). Go to: winzip.com/downwz.htm Click on Download Evaluation and then try to click on Save button using Python... I would be very –  Sasha May 25 '09 at 20:43
I would be very greatful if someone could help me with this... Thank you in advance. Sasha –  Sasha May 25 '09 at 20:44
Sasha, does this work with a program other than Winzip? It is possible that the Winzip program is intercepting the Win32 call and discarding it. –  Robert Harvey May 25 '09 at 20:50

It's possible that the save button is not always enabled. While it may look to your eye that it is, a program might see an initial state that you're missing. Check it's state and wait until it's enabled.

[EDIT] But it's possible that Robert is right and the dialog will just ignore you for security reasons. In this case, I suggest to use BeautifulSoup to parse the HTML, extract the URL and download the file in Python using the urllib2 module.

share|improve this answer
As I wrote previously the button is a regular windows button and not a part of html page. While downloading file, you get 'File Download' window open, with regular Open, Save, Cancel buttons. After pressing Save, windows opens Save As window where you write the file name and press another Save button. However, I am still stuck on the first window... –  Sasha May 25 '09 at 19:21
Updated my answer. But I guess Robert Harvey is right. –  Aaron Digulla May 26 '09 at 7:18

Your Answer


