Sign in to follow this  
Followers 0
jvish

Handling IE9 file download, activex prompts

10 posts in this topic

#1 ·  Posted (edited)

am trying to automate IE9 prompts for File Downlod, ActiveX download and other "Notification Bar" objects.

Unlike IE7/IE8 where the notification bars are Win32 - IE9 has this of type DIRECTUIHWND.

And I am not able to get the info of buttons, text etc from it.

Please check the attached picture. I need to capture the text from it & be able to click buttons on the yellow bar at the bottom of the browser.

Please let me know how this can be handled with AutoIT.

http://img130.imageshack.us/i/ie9filedownloadwindow.jpg/

Edited by jvish

Share this post


Link to post
Share on other sites



Adding the website to IE trusted sites and lowering the security settings of IE helps most of the time.

I dont have IE9 to test though.

Share this post


Link to post
Share on other sites

That works to fine if I want to suppress the notification bar.

But, I want to make sure it pops up & want to handle it. This used to be so easy on IE 8/IE 7

Share this post


Link to post
Share on other sites

Any updates on this? I am in the same situation with handling this new notification/information bar in IE9.

Share this post


Link to post
Share on other sites

Looks like there was a posted in July of this year about it. I'm referencing it here in case others come across the same problem.

I'm currently investigating this to see if I have any successes:

Share this post


Link to post
Share on other sites

So I finally was able to get a working solution for this. I wanted to post it here so others can refer to it if they come across the same issue.

Please note that I am doing my testing in a java framework so I am using the autoit jna wrapper that is defined here. The code could be easily transferred to autoit's native lang, but hopefully you will get the idea.

This code is assuming IE9 & Win7 environment.

Autoitx autoitx = getInstance();
//get a handle to the main window
byte[] retWin = new byte[9];
autoitx.AU3_WinGetHandle("[Class:IEFrame]", "", retWin, 9);
String winHandle = new String(retWin, 0, 8);
String winTitle = "[HANDLE:" + winHandle + "]"; 

//get a handle to the control (IE9 download info bar)
byte[] ctrlWin = new byte[9];
autoitx.AU3_ControlGetHandle(winTitle, "", "[Class:DirectUIHWND]", ctrlWin, 9);
String ctrlHandle = new String(ctrlWin, 0, 8);
String ctrlTitle = "[HANDLE:" + ctrlHandle + "]";

//must have this line in here in order to get a handle to the control
autoitx.AU3_WinWaitActive(ctrlTitle, "[CLASS:DirectUIHWND]", 10);

// Get the x, y coordinates of the control
x = autoitx.AU3_ControlGetPosWidth(winTitle, "", "[Class:DirectUIHWND]") - 135;  //will differ depending on size of control
y = autoitx.AU3_ControlGetPosHeight(winTitle, "", "[Class:DirectUIHWND]") - 25; //will differ depending on size of control
 
// Save Prompt
autoitx.AU3_ControlFocus(winTitle, "Do you want to open or save", "[CLASS:DirectUIHWND]");
autoitx.AU3_WinActivate(winTitle, "Do you want to open or save");
autoitx.AU3_ControlFocus(winTitle, "Do you want to open or save", "[CLASS:DirectUIHWND]");
autoitx.AU3_ControlClick(winTitle, "", "[Class:DirectUIHWND]", "primary", 1, x, y); //activates the save button
autoitx.AU3_ControlSend(winTitle, "", "[Class:DirectUIHWND]", "{Down}", 0); //down arrow 
autoitx.AU3_ControlSend(winTitle, "", "[Class:DirectUIHWND]", "a", 0); //select "save as"

// Save as dialog
autoitx.AU3_WinActivate("Save As", "Save");
autoitx.AU3_WinWaitActive("Save As", "Save", 10);
autoitx.AU3_ControlSetText("Save As", "", "Edit1", filepath);
autoitx.AU3_ControlClick("Save As", "", "&Save", "left", 1, 5, 5);
autoitx.AU3_ControlClick("Confirm Save As", "", "&Yes", "left", 1, 0, 0);
 
// Close the info bar
autoitx.AU3_WinActivate(winTitle, "");
x = autoitx.AU3_ControlGetPosWidth(winTitle, "", "[Class:DirectUIHWND]") - 15;
y = autoitx.AU3_ControlGetPosHeight(winTitle, "", "[Class:DirectUIHWND]") - 23;
autoitx.AU3_WinActivate(ctrlTitle, "");
autoitx.AU3_ControlClick(winTitle, "", "[Class:DirectUIHWND]", "", 1, x, y);
success = autoitx.AU3_ControlSend(winTitle, "", "[Class:DirectUIHWND]", "{Enter}", 0);

Share this post


Link to post
Share on other sites

Thanks Ellavader! I needed to click the Open button to launch a Citrix instance and I wrote the following in AutoIt Script:

Func ClickOpenInIEBar()
#cs
Credit to Ellavader at http://www.autoitscript.com/forum/topic/127987-handling-ie9-file-download-activex-prompts/
#ce
$retWin = WinGetHandle("[Class:IEFrame]", "")
$winTitle = "[HANDLE:" & $retWin & "]"
; get a handle to the control (IE9 download info bar)
$ctrlHandle = ControlGetHandle($winTitle, "", "[Class:DirectUIHWND]")
$ctrlTitle = "[HANDLE:" & $ctrlHandle & "]"

; must have this line in here in order to get a handle to the control
WinWaitActive($ctrlTitle, "[CLASS:DirectUIHWND]", 10);

$xy = ControlGetPos($winTitle, "", "[Class:DirectUIHWND]"); //will differ depending on size of control
$xpos = 730 ; $xy[2] - 160 ; depends on control size
$ypos = 25

; Open Prompt
WinActivate($winTitle, "Do you want to open or save");
ControlFocus($winTitle, "Do you want to open or save", "[CLASS:DirectUIHWND]");
ControlClick($winTitle, "", "[Class:DirectUIHWND]", "primary", 1, $xpos, $ypos); //activates the open button
; more magic - must send enter after click!!!
ControlSend($winTitle, "", "[Class:DirectUIHWND]", "{ENTER}", 0)
EndFunc

Share this post


Link to post
Share on other sites

It's ugly, but you can also do controlsend to the DirectX control: to use the button hot key. Probably Alt+O. No need to worry about missing the mouse click.


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Question... I am trying to implement a simple click on the "save as" option in the IE 10 "Do you want to save or open..." pop-up.  Is there a way to send the save as instruction directly to the pop-up?  If not is there a way to programatically determine the location of the save pull down and then select the save as?

Sorry don't know what the technical terms for these items are.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

#include <IE.au3>

;Global $l = 0
;https://employmenttribunalsni.co.uk/OITFET_IWS/DecisionSearch.aspx

;$j = 1 InputBox("Pages", "Enter the page number.", "", " M2")

$oIE = _IECreate("https://employmenttribunalsni.co.uk/OITFET_IWS/DecisionSearch.aspx")
Local $oForm = _IEFormGetObjByName($oIE, "DecisionSearch")
Local $oText = _IEFormElementGetObjByName($oForm, "txtDecisionIssuedYear")
_IEFormElementSetValue($oText, "2014")
Sleep(2000)
$oSubmit = _IEGetObjByName($oForm, "btnSearch")
_IEAction($oSubmit, "click")
_IELoadWait($oIE)

$sHTML = _IEDocReadHTML($oIE)
$i = 0
$nOffset = 1
While 1
    $i = $i + 1
    ;ClipPut($i)
    $array = StringRegExp($sHTML, '(?i)(?-s)<TD class="DataGridItem.*?>(0*\d+/\d+.*?)<.*?nowrap">(.*?)<.*?nowrap">(.*?)</TD>.*?DataGridItem2">(.*?)</TD>.*?DataGridItem2">.*?((\d+)\/(0*\d+)\/(\d+))(?s).*?INPUT name="(dgOnlineSearchResults.*?Doc)"', 1, $nOffset)

    ;02680/10IT     0
    ;Calvin     1
    ;Mark McMurdie Electrics<BR>     2
    ;Unauthorised Deduction of Wages<BR>Unfair Dismissal<BR>Other<BR>     3
    ;27/04/2011     4
    ;27     5
    ;04     6
    ;2011     7
    ;dgOnlineSearchResults__ctl3_OnlineDoc     8


    If @error = 0 Then
        $nOffset = @extended
    Else
        ExitLoop
    EndIf


    For $k = 0 To UBound($array) - 1
        ConsoleWrite($array[$k] & "   #1   " & $k & @CRLF)
    Next
    $OnlineDoc = $array[8]
    $array[0] = StringRegExpReplace($array[0], "/", "_")
    $array[6] = StringRegExpReplace($array[6], "01", " January ")
    $array[6] = StringRegExpReplace($array[6], "02", " February ")
    $array[6] = StringRegExpReplace($array[6], "03", " March ")
    $array[6] = StringRegExpReplace($array[6], "04", " April ")
    $array[6] = StringRegExpReplace($array[6], "05", " May ")
    $array[6] = StringRegExpReplace($array[6], "06", " June ")
    $array[6] = StringRegExpReplace($array[6], "07", " July ")
    $array[6] = StringRegExpReplace($array[6], "08", " August ")
    $array[6] = StringRegExpReplace($array[6], "09", " September ")
    $array[6] = StringRegExpReplace($array[6], "10", " October ")
    $array[6] = StringRegExpReplace($array[6], "11", " November ")
    $array[6] = StringRegExpReplace($array[6], "12", " December ")
    $array[1] = StringRegExpReplace($array[1], "<.*?>", " ")
    $array[2] = StringRegExpReplace($array[2], "<.*?>", " ")
    $title = $array[1] & ' v ' & $array[2] & ' [' & $array[7] & '] NI# ' & $array[0] & ' (' & $array[5] & ' ' & $array[6] & ' ' & $array[7] & ')'
    $oSubmit = _IEGetObjByName($oIE, $OnlineDoc)

    ClickOpenInIEBar()

;~             $hwnd = _IEPropertyGet($oIE, "hwnd")
;~              _IEAction($oSubmit, "focus")

;~          ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
;~          $dest = @MyDocumentsDir & '\AutoIt_code\getter\processing\out\'
;~          $filename2 = $j & '_' & $i

;~          WinWait("File Download")
;~          WinActivate("File Download")
;~          Sleep(500)

;~          ControlClick("File Download", "", "Button2") ; this clicks the default "save" button on the first dialog

;~          WinWait("Save As") ; Wait for the "Save As" box to pop up
;~          WinActivate("Save As")
;~          Sleep(500)

;~          $filename = ControlGetText("Save As", "Save &in:", "Edit1") ;Get the file name before we erase it
;~          ControlSetText("Save As", "Save &in:", "Edit1", "") ; erase the file name to make room for the $dest string
;~          Sleep(1000)

;~          ControlSetText("Save As", "Save &in:", "Edit1", $dest) ; set the Edit1 text to the $dest and hit the button to swithc directories.
;~          ControlClick("Save As", "", "Button2")
;~          Sleep(1000)

;~          ControlSetText("Save As", "Save &in:", "Edit1", $filename2) ; reset the name of the file to the original value.
;~          Sleep(1000)
;~          ControlClick("Save As", "", "Button2")
;~          _IEAction($oSubmit, "click")

;~          If $i < $j + 10 Then _IEAction($oSubmit, "quit")

;~          $file = FileOpen(@MyDocumentsDir & '\AutoIt_code\getter\processing\' & $j & '_' & $i & ".txt", 2)
;~          FileWrite($file, $title)
;~          FileClose($file)

WEnd
$i = 0
;$j = $j + 1
$oNext = _IEGetObjById($oIE, "cmdNext")
_IEAction($oNext, "click")
_IELoadWait($oIE)
$sHTML = _IEDocReadHTML($oIE)

Func ClickOpenInIEBar()
    #cs
        Credit to Ellavader at <a href='http://www.autoitscript.com/forum/topic/127987-handling-ie9-file-download-activex-prompts/' class='bbc_url' title=''>http://www.autoitscript.com/forum/topic/127987-handling-ie9-file-download-activex-prompts/</a>
    #ce
    $retWin = WinGetHandle("[Class:IEFrame]", "")
    $winTitle = "[HANDLE:" & $retWin & "]"
    ; get a handle to the control (IE9 download info bar)
    $ctrlHandle = ControlGetHandle($winTitle, "", "[Class:DirectUIHWND]")
    $ctrlTitle = "[HANDLE:" & $ctrlHandle & "]"

    ; must have this line in here in order to get a handle to the control
    WinWaitActive($ctrlTitle, "[CLASS:DirectUIHWND]", 10);

    $xy = ControlGetPos($winTitle, "", "[Class:DirectUIHWND]"); //will differ depending on size of control
    $xpos = 730 ; $xy[2] - 160 ; depends on control size
    $ypos = 25

    ; Open Prompt
    WinActivate($winTitle, "Do you want to open or save");
    ControlFocus($winTitle, "Do you want to open or save", "[CLASS:DirectUIHWND]");
    ControlClick($winTitle, "", "[Class:DirectUIHWND]", "primary", 1, $xpos, $ypos); //activates the open button
    ; more magic - must send enter after click!!!
    ControlSend($winTitle, "", "[Class:DirectUIHWND]", "{ENTER}", 0)
EndFunc   ;==>ClickOpenInIEBar

I'm trying to update one of my scripts that would gather information on a document and download the .doc file.  As this topic shows this is no longer easy with IE9.  I've successfully used Ellavader's function for an easy InetGet download solution but this is a difficult website do download from as every file to be downloaded has the same Obj Name.  You can see the old script bits commented out in the script above but I just can't figure where  Ellavader's function would come in and how to  download/save the file in a specific directory with the filename as $array[0] & ".doc". I'm quite happy to do this with Firefox and have got as far as getting all the information necessary but again it is the difficulty with these files having the same Obj Name that stumps me (also I can't see how to download/save the file in a specific directory with the filename as $array[0] & ".doc" using the FF UDF) here is my script for FF:

#include <FF.au3>
;see: http://english.documentation.ff-au3.thorsten-willert.de/
#include <Array.au3>

$processing = @MyDocumentsDir & '\AutoIt_code\getter\processing\'
$out = @MyDocumentsDir & '\AutoIt_code\getter\processing\out\'

_FFAu3Option("ComTrace", False)

$url1 = 'https://employmenttribunalsni.co.uk/OITFET_IWS/(c2cxvf45cfjhbz553phcjy45)/DecisionSearch.aspx'
_FFStart($url1, Default, 2)
_FFConnect(Default, Default, 3000)

Sleep(3000)

$sInput = _FFObjGet("txtDecisionIssuedYear", "name") ; returns a string - no object!
_FFObj($sInput, "value", "2014")
Sleep(1000)
_FFDispatchEvent(_FFObjGet("btnSearch", "id"), "keypress", 13)
Sleep(3000)


$sHTML = _FFReadHTML()

Sleep(1000)
$aArray = StringRegExp($sHTML, '(?i)(?-s)(<TD class="DataGridItem.*?(?s).*?INPUT name=.dgOnlineSearchResults.*?Doc.)', 3)
For $i = 0 To UBound($aArray) - 1
$bArray = StringRegExp($aArray[$i], '(?i)(?-s)<TD class="DataGridItem.*?>(0*\d+/\d+.*?)<.*?nowrap">(.*?)<.*?nowrap">(.*?)</TD>.*?DataGridItem2">(.*?)</TD>.*?DataGridItem2">.*?((\d+)\/(0*\d+)\/(\d+))(?s).*?INPUT name="(dgOnlineSearchResults.*?Doc)"', 3)
;For $k = 0 To UBound($bArray) - 1
;    ConsoleWrite($k &" "& $bArray[$k] &  @CRLF)
;Next
    $OnlineDoc = $bArray[8]
    $bArray[0] = StringRegExpReplace($bArray[0], "/", "_")
    $bArray[6] = StringRegExpReplace($bArray[6], "01", " January ")
    $bArray[6] = StringRegExpReplace($bArray[6], "02", " February ")
    $bArray[6] = StringRegExpReplace($bArray[6], "03", " March ")
    $bArray[6] = StringRegExpReplace($bArray[6], "04", " April ")
    $bArray[6] = StringRegExpReplace($bArray[6], "05", " May ")
    $bArray[6] = StringRegExpReplace($bArray[6], "06", " June ")
    $bArray[6] = StringRegExpReplace($bArray[6], "07", " July ")
    $bArray[6] = StringRegExpReplace($bArray[6], "08", " August ")
    $bArray[6] = StringRegExpReplace($bArray[6], "09", " September ")
    $bArray[6] = StringRegExpReplace($bArray[6], "10", " October ")
    $bArray[6] = StringRegExpReplace($bArray[6], "11", " November ")
    $bArray[6] = StringRegExpReplace($bArray[6], "12", " December ")
    $bArray[1] = StringRegExpReplace($bArray[1], "<.*?>", " & ")
    $bArray[2] = StringRegExpReplace($bArray[2], "<.*?>", " & ")
    $bArray[3] = StringRegExpReplace($bArray[2], "<.*?>", " : ")
    $title = $bArray[1] & ' v ' & $bArray[2] & ' [' & $bArray[7] & '] NI# ' & $bArray[0] & ' (' & $bArray[5] & ' ' & $bArray[6] & ' ' & $bArray[7] & ')'
    ConsoleWrite($title & @CRLF)
    InetGet("https://employmenttribunalsni.co.uk/OITFET_IWS/(c2cxvf45cfjhbz553phcjy45)/OnlineDecisionDocument2.aspx", $processing & $bArray[0] & ".doc")
Next
;~ 0    01293/13IT
;~ 1    Sharkey
;~ 2    GarCel NI Ltd<br>
;~ 3    Unfair Dismissal<br>Other<br>Discrimination - Age<br>Breach of Contract<br>Unauthorised Deduction of Wages<br>
;~ 4    08/08/2014
;~ 5    08
;~ 6    08
;~ 7    2014
;~ 8    dgOnlineSearchResults:_ctl3:OnlineDoc
;       <input name="dgOnlineSearchResults:_ctl12:OnlineDoc" id="dgOnlineSearchResults__ctl12_OnlineDoc" title="View Online Decision" src="Images/word_icon.jpg" alt="" border="0" align="Middle" type="image">
Edited by Jury

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