Jump to content
Sign in to follow this  
az2000

IE download save/open dialog. How to access?

Recommended Posts

az2000

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!

Share this post


Link to post
Share on other sites
mLipok

see that

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

edit:

sorry no this kind of problem

Edited by mlipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for 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
 

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 *

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 * 

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 TaskScheduler

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 *

"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: 2018-10-31

Share this post


Link to post
Share on other sites
az2000

(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

Share this post


Link to post
Share on other sites
DW1

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
  • Like 2

Share this post


Link to post
Share on other sites
AutID

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

Share this post


Link to post
Share on other sites
DW1

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.

Share this post


Link to post
Share on other sites
AutID

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.

Share this post


Link to post
Share on other sites
DW1

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.

Share this post


Link to post
Share on other sites
AutID

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!

Share this post


Link to post
Share on other sites
DW1

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

Share this post


Link to post
Share on other sites
az2000

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!

Share this post


Link to post
Share on other sites
DW1

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.

Share this post


Link to post
Share on other sites
az2000

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.

Share this post


Link to post
Share on other sites
JohnGetzke

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.

Share this post


Link to post
Share on other sites
JohnGetzke

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

Share this post


Link to post
Share on other sites
JohnGetzke

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

Share this post


Link to post
Share on other sites
duncanpt

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.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

  • Similar Content

    • TLAM
      By TLAM
      Hello,
      I am working on an autoIT script for CyberArk which is running Internet Explorer and connecting the user to a web application.
      For an unknown reason (I cannot explain why), IE has some trouble to start, only after a long disconnecting period (morning or after lunch). If he tries again, no problem, IE starts.
      I open a case with CyberArk but I am also searching a workaround, I thought to kill the process directly, or set a timeout with _IELoadWait but the process is not really created..

      May do you have any ideas for helping me ?

      Thanks in advance
       
    • Seminko
      By Seminko
      Wrote a script that grabs all of the IP addresses from Netflix's IP log, checks the IPs and returns suspicious activity.
      Everything works as it should but only when _IECreate is set to visible. When visible is set to false, it fails to login for some reason.
      Any ideas what might cause it and/or how to circumvent that?
    • nooneclose
      By nooneclose
      I need to send a string of text to this popup and click on the ok button to save it.
      Here is the code I have so far:
      ;Start IE Sleep(7000) $oIE = _IECreate("http://www.google.com") Sleep(500) _IELoadWait($oIE) $hIE = _IEPropertyGet($oIE, "hwnd") ; Get Handle of the IE window Sleep(500) WinSetState($hIE, "", @SW_MAXIMIZE) ;Wait for a browser page load to complete Sleep(3000) _IENavigate($oIE, "https://properURL.com") Sleep(8000) _IELoadWait($oIE) ;Attach to a browser control embedded in another window $oIE = _IEAttach("https://"properURL.com", url") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $oIE = ' & $oIE & @CRLF & '>Error code: ' & @error & ' Extended code: 0x' & Hex(@extended) & @CRLF) ;### Debug Console Sleep(2000) ;Get the title of the webpage ;Local $wTitle = _IEPropertyGet($oIE, "title") ;MsgBox($MB_SYSTEMMODAL, "Webpage title:", $wTitle) ;Clicks the new button Sleep(3000) _IEAction($nWorkOrderB, "focus") _IEAction($nWorkOrderB, "click") Sleep(5000) ;Store the Element names where the important data will be sent ;Store the long description button Local $wLongDButton = _IEGetObjById($oIE, "m65d795a4-img") ;Store the long Description field id Local $wComments = _IEGetObjById($oIE, "ma6499a9c-rte_iframe") ;Store the ok button id that is in the long description Local $wCommOk = _IEGetObjById($oIE, "m74031266-pb") ;******************************************************************************* ; Send the stored data to the proper field ;******************************************************************************* ;Click the long description button Sleep(300) _IEAction($wLongDButton, "focus") _IEAction($wLongDButton, "click") Sleep(300) ;Sends the Comments Sleep(500) _IEAction($wComments, "focus") _IEAction($wComments, "click") Sleep(500) _IEFormElementSetValue($wComments, "hello darkness my old friend") ;Click the ok button Sleep(500) _IEAction($wCommOk, "focus") _IEAction($wCommOk, "click") Sleep(500)  
      Here is the popup:

    • hemichallenger
      By hemichallenger
      Hello,
      If anyone can help, it would be greatly appreciated. The code is just an example and similar to the issue with an internal webpage. I'm trying to autofill than click the submit button. I get the same error running the script.
      _IEFormElementSetValue, $_IESTATUS_InvalidObjectType
      IEGetObjById, $_IESTATUS_NoMatch
      Is it possible to edit the <textarea></textarea>  field with AutoIt?  If anyone could assist me on how. Than I could have a better understanding and chance in figuring it out on my main script. Thank you
      #include <IE.au3> Local $oIE1 = _IECreate ("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_textarea") _IELoadWait($oIE1) local $oFormCollection = _IEFormGetCollection($oIE1,0) local $oid = _IEGetObjByid($oFormCollection, "iframeResult") _IEFormElementSetValue($oid, "test") sleep (2000) Local $oIE2 = _IECreate ("https://www.w3schools.com/html/tryit.asp?filename=tryhtml_scripts_intro") _IELoadWait($oIE2) $oForm2 = _IEFormGetCollection($oIE2,0) $oClickMe = _IEGetObjById($oForm2, "demo") _IEAction($oClickMe, "focus") _IEAction($oClickMe, "click")
×