Jump to content

IE download save/open dialog. How to access?


Go to solution Solved by az2000,

Recommended Posts

Posted

When I click a link to download a file in IE 9, the browser displays a small popup at the bottom of the page, asking to save/open/cancel. I can't figure out how to interact with that. It's not really a window. It's not really part of the HTML page either. It's something else.

What I want to do is close/cancel the download before it even starts. I can't figure out how to send a keystroke to do it, nor click the cancel button.

AutoIT: 3.3.8.1

IE: 9.0.8

Thanks!

Posted (edited)

see that

'?do=embed' frameborder='0' data-embedContent>>

edit:

sorry no this kind of problem

Edited by mlipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)
  On 9/10/2013 at 9:11 PM, mlipok said:

(sorry no this kind of problem)

 

Yes, I'm able to interact with the Save As dialog. That's a real window. This download/confirm thing is weird. It's like an absolutely positioned layer of the page being viewed. It's the same thing as when a page has Active X (and IE informs you it's disabled, or asks if you want to enable it).

Edited by az2000
Posted

It's not pretty, in fact, I think it's downright ugly, but it works in IE10 (likely 9 as well).

Here is to hoping somebody swoops in and proposes a better solution.

AdlibRegister("AutoCancel")

While 1
    Sleep(10)
WEnd

Func AutoCancel()
    If WinActive("[Class:IEFrame]") Then
        Local $hIE = WinGetHandle("[Class:IEFrame]")
        Local $hCtrl = ControlGetHandle($hIE, "", "[ClassNN:DirectUIHWND1]")
        Local $aPos = ControlGetPos($hIE, "", $hCtrl)
        Local $aWinPos = WinGetPos($hIE)
        If ControlCommand($hIE, "", $hCtrl, "IsVisible") And $aPos[1] > .75 * $aWinPos[3] Then ; Check if the control is in the bottom 25% of the page.
            ControlClick($hIE, "", $hCtrl, "primary", 1, $aPos[2] - 70, $aPos[3] - 30)
            Sleep(500)
            ControlSend($hIE, "", $hCtrl, "{enter}")
        EndIf
    EndIf
EndFunc   ;==>AutoCancel
Posted

Why use ie automatin to download a file.

I would do something like this:

Global $path = @DesktopDir & "\test.exe"
$Surl = "http://download.thinkbroadband.com/5MB.zip"
FileDownload($Surl, $path)
Func FileDownload($url, $SavePath)
Local $xml, $Stream
$xml = ObjCreate("Microsoft.XMLHTTP"); Corrected from winhttp.winhttprequest.5.1 for faster dl
$Stream = ObjCreate("Adodb.Stream")
$xml.Open("GET", $url, 0)
$xml.Send
$Stream.Type = 1
$Stream.Open
$Stream.write($xml.ResponseBody)
$Stream.SaveToFile($SavePath)
$Stream.Close
EndFunc ;==>FileDownload

or even INetGet would do ;)

Posted

  On 9/11/2013 at 12:30 AM, AutID said:

Why use ie automatin to download a file.

I would do something like this:

 

  On 9/10/2013 at 8:25 PM, az2000 said:

What I want to do is close/cancel the download before it even starts. I can't figure out how to send a keystroke to do it, nor click the cancel button.

 

I think you must have misunderstood what the OP was asking for.  He needs to interact with the save/open/cancel dialog in IE9/10, not download a file.

Posted

  On 9/11/2013 at 1:27 AM, danwilli said:

I think you must have misunderstood what the OP was asking for.  He needs to interact with the save/open/cancel dialog in IE9/10, not download a file.

Oups ;)

That control has a handle. It should be easy to handle. Besides there must be a link in the ie that should activate/disactivate it.

Posted

  On 9/11/2013 at 1:48 AM, AutID said:

Oups ;)

That control has a handle. It should be easy to handle. Besides there must be a link in the ie that should activate/disactivate it.

By all means, give it a shot.  It wants to resist some automation as it's a security dialog.  The script I provided works, it's just not a very clean solution.  If you can find a way to deactivate it or automate it, other than the method I posted, I would love to see it and learn from it.  I'm hoping there is indeed a way, but it is not as simple as it appears at first glance.

Posted (edited)
  On 9/11/2013 at 2:30 AM, AutID said:

Well I took a simple look at it and seems that C keystroke can cancel it. Just send a control command of ALT + C to that window and voila!

Good find, I was over complicating it by converting a script I wrote to do the "Save As" in the same dialog box.

EDIT: Actually, after testing it, this doesn't work as expected, even when manually pressing ALT + C, it will only open the favorites menu.  Good thought, but I figured you had tested it.  If you did test it, can you provide the code you used?

Edited by danwilli
Posted
  On 9/11/2013 at 2:30 AM, AutID said:

Well I took a simple look at it and seems that C keystroke can cancel it. Just send a control command of ALT + C to that window and voila!

 

That sounded like a great idea. But, when I try it, IE catches the ALT+C and thinks its a keystroke to open the "Favorites" pane.

Here's what I'm using:

Local $hIE2 = WinGetHandle("[Class:IEFrame]")
Local $hCtrl = ControlGetHandle($hIE2, "", "[ClassNN:DirectUIHWND1]")

ControlSend($hIE2, "", $hCtrl, "!C")

I'm going to try Dan's solution now. But, I'd be happy to do something simpler if you can figure out how ControlSend could work. Thanks!

Posted
  On 9/12/2013 at 12:25 AM, az2000 said:

That sounded like a great idea. But, when I try it, IE catches the ALT+C and thinks its a keystroke to open the "Favorites" pane.

Here's what I'm using:

Local $hIE2 = WinGetHandle("[Class:IEFrame]")
Local $hCtrl = ControlGetHandle($hIE2, "", "[ClassNN:DirectUIHWND1]")

ControlSend($hIE2, "", $hCtrl, "!C")

I'm going to try Dan's solution now. But, I'd be happy to do something simpler if you can figure out how ControlSend could work. Thanks!

I'm actually seeing the same behavior with sending !c.  Even after a button within that dialog is highlighted the !c combo just opens my favorites as well.  The solution I originally posted is still working for me in IE9 and IE10.

  • Solution
Posted
  On 9/12/2013 at 1:16 AM, danwilli said:

The solution I originally posted is still working for me in IE9 and IE10.

 

I used your controlClick last night and it worked perfect. Thanks!

I didn't realize ControlClick has an x/y positioning. I thought I had to click the control handle, otherwise resort to moving the mouse to x/y and doing a mouse click. ControlClick's a lot nicer than what I thought I'd have to do.

  • 5 months later...
Posted

Hello,

The code from DW1 works great for selecting the Cancel button on the IE Do you want to open or save xxxxx from zzzzz popup.

How can I modify it so that it selects the Save As option?  This one is tucked under the default Save option.  I'm not familiar with the X, Y coordinate targeting system of ControlClick.

Posted

Well I originally intended to go to the Save As option, however the X,Y coordinate feature was giving me some grief.  I managed to hit the normal Save button and now think that button will actually work better.  When you click the Save button IE automatically saves the content to your Downloads folder (C:users<userid>Downloads).  It is much easier to write a some follow up logic to find that file and move it manually than it is to have IE save it directly to a specific location.  Less screen clicks and faster that way, assuming your default downloads folder doesn't ever change.

I measured the window with a ruler on my screen and then displayed the $apos[2] and compared the two.  This allowed me to estimate approximately how many pixels across the screen the button was located from the edge of the control.  I used $aPos[2] - 150 and it is working fine.

Here's my code for the Save button:

If WinActive("[Class:IEFrame]") Then
    Local $hIE = WinGetHandle("[Class:IEFrame]")
    Local $hCtrl = ControlGetHandle($hIE, "", "[ClassNN:DirectUIHWND1]")
    Local $aPos = ControlGetPos($hIE, "", $hCtrl)
    Local $aWinPos = WinGetPos($hIE)

  ; Check if the control is in the bottom 25% of the page.  
  If ControlCommand($hIE, "", $hCtrl, "IsVisible") And $aPos[1] > .75 * $aWinPos[3] Then 
      ControlClick($hIE, "", $hCtrl, "middle", 1, $aPos[2] - 150, $aPos[3] - 30)
      Sleep(500)
      ControlSend($hIE, "", $hCtrl, "{enter}")
    EndIf
  EndIf
Posted (edited)

Hello again,

While the code from above has been working great on my primary machine when I kick it off by hand my real goal is to have a fully automated solution.  This would require the use of a virtual machine periodically calling my script every few hours and checking for updates on a website.  From what I have seen the ControlClick method is not able to run when a user is not technically sitting at and viewing the desktop.  My guess is that even though the user is signed in the screen is still technically sitting behind the Windows lock screen and the clicks do not make it to the IE browser.

A work around for full automation is to rely completely on ControlSend which can be run from the Task Scheduler.  The code is actually much simpler considering what I have learned about the IE Handles and behavior involved.

Here's the code for the Save button using Tabs:

;If you wait long enough then IE9 will automatically give focus to the Save As popup box
  Sleep(10000)
  
  Local $hIE = WinGetHandle("[Class:IEFrame]")
  Local $hCtrl = ControlGetHandle($hIE, "", "[ClassNN:DirectUIHWND1]")
  ControlSend($hIE ,"",$hCtrl,"{TAB}")          ; Gives focus to Open Button
  Sleep(500)
  ControlSend($hIE ,"",$hCtrl,"{TAB}")          ; Gives focus to Save Button
  Sleep(500)
  ControlSend($hIE ,"",$hCtrl,"{enter}")        ; Submit whatever control has focus
  
  ;Give IE enough time to complete the download before proceeding
  Sleep(10000)

As I noted, if you watch the behavior of the IE Save As popup you will notice that it will flash Orange once it is ready.  This is what you need to wait for before sending your TAB and ENTER keys.  I assume these hard coded sleeps will need to adjust depending on the download.  I happen to be downloading a 45K CSV file with my code.

Edited by JohnGetzke
  • 9 months later...
Posted

I read the above and wasn't sure it would work for me - I need the script to work on a range of users' machines and without expecting them to interact with it.

So I searched for general keyboard interaction with this notification bar. Turns out the answer is simple.

While the notification bar is displayed (that is the Open/Save/Cancel frame), Alt-N give it proper focus and then a sequence of TABs will select Open, then Save, then Cancel.

Therefore once the notification bar triggered to appear, it's a simple matter of

Send("!n{TAB 3}{ENTER}")

to select the Cancel button.

  • 8 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...