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 *
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 API *

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 *

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

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-03-17

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

    • FMS
      By FMS
      Hello,
      I try to get all the text from a news site around a subject.
      The first run I get all the text inside a attribute in an array.
      When i try to go back and reload another page it chrashes and think it because "$oIE.GoBack"
      I couldn't find anything in the help/forum around this subject.
      Do I need to reload the $oIE or something afther an X.GoBack?
      The error i got is :
      if $oTag2.GetAttribute("class") == "NewsDetail" Then if $oTag2^ ERROR I'm not shure why I got this error, maybe someone could explain?
      Also I'm open for some pointers in this test script because I'm pretty new in working whit the IE.UDF
      Maybe there is an simpler way to get the same results?

      test script:
      #include <IE.au3> #include <MsgBoxConstants.au3> #include <Array.au3> HotKeySet("{ESC}", "Terminate") Global $oIE = _IECreate("https://www.iex.nl/Zoeken/Nieuws.aspx?q=air%20france") ;get first subject Global $oLink1 = _IEGetObjById($oIE, "ctl00_ctl00_Content_LeftContent_NewsSearch_repNews_ctl00_linkNews") Sleep(500) _IEAction($oLink1, "click") Sleep(500) Global $oTags = _IETagNameGetCollection($oIE, "div") Global $aResults[1] For $oTag In $oTags if $oTag.GetAttribute("class") == "NewsDetail" Then _ArrayAdd($aResults, $oTag.innerTEXT) EndIf Next $aResults[0] = UBound($aResults) - 1 _ArrayDisplay($aResults, "Episodelist") ConsoleWrite($aResults[1] & @CRLF) $oIE.GoBack ;get second subject Global $oLink2 = _IEGetObjById($oIE, "ctl00_ctl00_Content_LeftContent_NewsSearch_repNews_ctl01_linkNews") Sleep(500) _IEAction($oLink2, "click") Sleep(500) Local $oTags2 = _IETagNameGetCollection($oIE, "div") Local $aResults2[1] For $oTag2 In $oTags2 if $oTag2.GetAttribute("class") == "NewsDetail" Then _ArrayAdd($aResults2, $oTag2.innerTEXT) EndIf Next $aResults2[0] = UBound($aResults2) - 1 ConsoleWrite($aResults2[1] & @CRLF) Func Terminate() _IEQuit($oIE) Exit EndFunc ;==>Terminate  
    • nacerbaaziz
      By nacerbaaziz
      Hello
      Can we pause and resume the download in the InetGet function?
      If is possible, what is the solution please?
      I used this code To manage the download

      #include <INet.au3> func _downloader($name, $linc, $filepath, $RTLF = false, $link = false) global $downloader = GUICreate("downloader", 400, 200, -1, -1, $WS_CLIPCHILDREn, $RTLF, $link) global $path = $filePath $labelTxt = GUICtrlCreateLabel("downloading " & $name, 50, 10, 200, 20) global $labelTxt0 = GUICtrlCreateLabel("downloaded size 0 MB " & "OF 0 MB", 50, 60, 300, 20) global $Progress = "" global $sText = ""     For $i = 1 To Random(5, 20, 1) ; Return an integer between 5 and 20 to determine the length of the string.         $sText &= Chr(Random(65, 122, 1)) ; Return an integer between 65 and 122 which represent the ASCII characters between a (lower-case) to Z (upper-case). next global $labelTxt2 = GUICtrlCreateInput("0%", 50, 80, 50, 20) _GUICtrlEdit_SetReadOnly(-1, true) GUIStartGroup("") global $beep = GUICtrlCreateCheckBox("use the progress beep notification", 150, 120, 200, 20) GUIStartGroup("") $button = GUICtrlCreateButton("Cancel', 130, 150, 180, 25, 0x01) $iIndex = 0 global $Target global $url GUIStartGroup("") global $Progress = GUICtrlCreateProgress(50, 90, 150, 20) global $Target = $filepath global $url = $linc global $path = $filepath global $hDownloadNo = _RSMWare_GetData($url, $Target) global $status = false AdlibRegister("SetProgress") global $onprogress = false, $curent = false GUISetState(@sw_Show) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $button $asc = MsgBox(4132,"exit download?","if you click yes the downloading will be cancel, do you want to cancel it ?") if $asc = 6 then AdlibUnRegister("SetProgress") GUIDelete() If $hDownloadNo <> 0 Then InetClose($hDownloadNo) exitLoop endIf EndSwitch if $status = -1 then $status = 0 $hDownloadNo = _RSMWare_GetData($url, $Target) $onprogress = false $curent = false elseIf $Status = 1 then $status = $path GUIDelete() AdlibUnRegister("SetProgress") exitLoop endIf WEnd return $status endFunc Func _RSMWare_GetData($url, $Target) Local $hDownload = InetGet($url, $Target, 1, 1) Return $hDownload EndFunc ;==>_RSMWare_GetData Func SetProgress() Local $state If $hDownloadNo <> 0 Then $state = InetGetInfo($hDownloadNo) If @error = 0 Then $infor = "downloaded size " & Round(Execute(InetGetInfo($hDownloadNo, $INET_DOWNLOADREAD) / 1048576), 2) & " MB of " & Round(Execute(InetGetInfo($hDownloadNo, $INET_DOWNLOADSIZE) / 1048576), 2) & " MB " $onprogress = Round(Ceiling(($state[0] / $state[1]) * 100)) if not (InetGetInfo($hDownloadNo, $INET_DOWNLOADSIZE) = 0) then if $onProgress <= 0 then $onProgress = 0 GUICtrlSetData($Progress, $onProgress) GUICtrlSetData($labelTxt0, $infor) GUICtrlSetData($labelTxt2, $onProgress & "%") if _isChecked($beep) then if $onprogress > $curent then beep((100 + $onprogress * 20), 100) $curent = $onprogress endIf endIf endIf If $state[2] Then If $state[3] Then InetClose($hDownloadNo) $status = 1 else InetClose($hDownloadNo) $status = -1 endIf endIf EndIf endIf EndFunc ;==>SetProgress
    • SkysLastChance
      By SkysLastChance
      I am having a hard time understanding why this is not working. I was hoping some one could help explain it to me. 
      $tags = $oIE.document.GetElementsByTagName("input") For $tag in $tags $class_value = $tag.GetAttribute("class") If string($class_value) = "fTs-p3298-l0 wplEditControl" Then $target = $tag ExitLoop EndIF Next MsgBox(0,"",$target) If $target = "fTs-p3298-l0 wplEditControl" THEN MsgBox(0,"","itworked") I have tried 
       MsgBox(0,"",$target.Attribute)  MsgBox(0,"",$target.Value)  MsgBox(0,"",$target.InnerText) I would expect to see this in the msgbox
      fTs-p3298-l0 wplEditControl  
    • SkysLastChance
      By SkysLastChance
      I am trying to grab the id "in2xk_26" however it the characters before the underscore always change. (in the name too)
      Is there a way I can find a id or name by the last 3 charcters?
      Using something like "stringright?"
      So I would want to search for just "_26" in this case.
      This is assuming that there are no other _26
       

      #include <Excel.au3> #include <IE.au3> #include <GUIConstantsEx.au3> Global $iMousespeed = 25,$target = "",$TagName = "",$Value = "",$Atrribute = "" $oIE = _IEAttach("MEDITECH") $TagName = "input" $Value = "in2xk_26" $Attribute = "id" $tags = $oIE.document.GetElementsByTagName($TagName) ;TagName ------ MAKE SURE TO NAME THESE For $tag in $tags $class_value = $tag.GetAttribute($Attribute) ;Attribute ------ MAKE SURE TO NAME THESE If string($class_value) = $Value Then ;Value ------ MAKE SURE TO NAME THESE $target = $tag $iScreenX = _IEPropertyGet($target, "screenx") $iScreenY = _IEPropertyGet($target, "screeny") $iWidth = _IEPropertyGet($target, "width") $iHeight = _IEPropertyGet($target, "height") $oMouseCords = MouseMove($iScreenX + $iWidth / 2, $iScreenY + $iHeight / 2, $iMousespeed) MouseClick($MOUSE_CLICK_LEFT) ExitLoop EndIf Next  
       
    • SkysLastChance
      By SkysLastChance
      I was wondering how I read data inside of a iframe. I would like to be able to click something inside a iframe. However, I can't even find the tag. 
      The id and name change all the time so I can't use those. 
      The code highlighted in blue is what I am trying to click. (second picture)
      Here is what I have tried.
      $target = "" $tags = $oIE.document.GetElementsByTagName("div") For $tag in $tags $class_value = $tag.GetAttribute("class") If string($class_value) = "s_92 altstyle s_93 s_94" Then $target = $tag ConsoleWrite("Tag Found " & $target.outerText&@CRLF) ExitLoop EndIf Next  

       
       

×