Jump to content

IE download save/open dialog. How to access?


az2000
 Share

Go to solution Solved by az2000,

Recommended Posts

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!

Link to comment
Share on other sites

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:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

(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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 ;)

Link to comment
Share on other sites

Why use ie automatin to download a file.

I would do something like this:

 

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Solution

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.

Link to comment
Share on other sites

  • 5 months later...

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 9 months later...

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.

Link to comment
Share on other sites

  • 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
 Share

×
×
  • Create New...