Jump to content

Save download with IE hidden/invisible


Recommended Posts

Hello Folks,

I've searched all related posts, maybe spanning 6 years back, and couldn't get around that

I'm automating a download button on the enclosed url. The button executes a javascript and uses a session-attached cookie. That's as far as I could get as I'm not into front-end. 

Bottom line; I couldn't get to download the file another way than GUI automation

Now, the below script clicks on download succesfully, even if IE is hidden (to avoid end user interruption). However, I cannot send keystrokes to the open/save control while IE is still hidden. Even if the control takes focus, it won't work unless IE becomes visible again.

I added comments for easier perusal. Your help is really appreciated.

P.S. I'm fiddling also with SecondDesktop script from here, but still no success

#include <IE.au3>

; change first 0 to 1 to run IE visible
$oIE = _IECreate("https://www.eclaimlink.ae/NoneRegisteredCodingSets.aspx", 1, 0, 0)


_IELoadWait($oIE)
$myTitle = _IEPropertyGet($oIE, "title") ; Grab Title of IE window



    Sleep (500)
$oIE = _IEAttach($myTitle)
$oDiv1 = _IEGetObjById($oIE, "ContentPlaceHolder1_NoneRegisteredCodingSetsUC1_GridView1_btnDownload_10")
_IEAction($oDiv1, "click")


; get the handle of main window
Local $windHandle= WinGetHandle("[Class:IEFrame]", "")
Local $winTitle = "[HANDLE:" & $windHandle & "]"





$rtrnFocus = ControlFocus($winTitle,"","DirectUIHWND1" ) ;changes focus to open/save dialoge box control

;MsgBox(1,"",$rtrnFocus); for testing, returns 1 for successful focus control
;_IEAction($oIE, "visible")
; the following send actions only work properly if IE is visible
; It does not matter even if control ClassNameNN is added to ControlSend parameters

WinActivate($myTitle)
ControlSend($winTitle, "", "", "{F6}")
Sleep(500)
ControlSend($winTitle, "", "", "{TAB}")
Sleep(500)
ControlSend($winTitle, "", "", "{Enter}")


;_IEAction($oIE, "invisible")

_IEQuit($oIE)

 

Link to comment
Share on other sites

One way, not perfect but working :

#include <Constants.au3>
#include <IE.au3>
#include "..\BlockInput\BlockInputEx.au3" ; ;https://www.autoitscript.com/forum/topic/199762-udf-blockinputex/

$oIE = _IECreate("https://www.eclaimlink.ae/NoneRegisteredCodingSets.aspx", 0, 0)
$oDiv1 = _IEGetObjById($oIE, "ContentPlaceHolder1_NoneRegisteredCodingSetsUC1_GridView1_btnDownload_10")
_IEAction($oDiv1, "click")

Sleep (800)

Local $hWnd= _IEPropertyGet ($oIE, "hwnd")
Local $hCtrl = ControlGetHandle ($hWnd, "", "DirectUIHWND1")
ConsoleWrite ("Control = " & $hCtrl & @CRLF)

_BlockInput ($BI_DISABLE)
$oIE.visible = True
Sleep (800)
ConsoleWrite (ControlSend ($hWnd, "", $hCtrl, "{F6}{TAB}") & @CRLF)
Sleep (800)
ControlSend ($hWnd, "", $hCtrl, "{ENTER}")
$oIE.visible = False
_BlockInput ($BI_ENABLE)

Sleep (1000)
_IEQuit ($oIE)

 

Link to comment
Share on other sites

Thank you for this neat idea & UDF @Nine It will come handy in other scripts too. It works and IE window shows briefly for 2 seconds.

However, when I comment out  visible functions (i.e script runs with completely hidden IE till the end), the control does not receive keystrokes and nothing downloaded.

My ultimate target is to click on 'Save' and close IE without anything displayed to end user. Could this be achieved some how ?

Link to comment
Share on other sites

I think this is the closest we can get to hide the download :

#include <Constants.au3>
#include <IE.au3>
#include "..\BlockInput\BlockInputEx.au3" ; ;https://www.autoitscript.com/forum/topic/199762-udf-blockinputex/

$oIE = _IECreate("https://www.eclaimlink.ae/NoneRegisteredCodingSets.aspx", 0, 0)
$oDiv1 = _IEGetObjById($oIE, "ContentPlaceHolder1_NoneRegisteredCodingSetsUC1_GridView1_btnDownload_10")
_IEAction($oDiv1, "click")

Sleep (800)

Local $hWnd= _IEPropertyGet ($oIE, "hwnd")
Local $hCtrl = ControlGetHandle ($hWnd, "", "DirectUIHWND1")
ConsoleWrite ("Control = " & $hCtrl & @CRLF)
WinSetTrans ($hWnd, "", 0)

_BlockInput ($BI_DISABLE)
$oIE.visible = True
WinActivate ($hWnd)
Sleep (800)
ConsoleWrite (ControlSend ($hWnd, "", $hCtrl, "{F6}{TAB}") & @CRLF)
Sleep (800)
ControlSend ($hWnd, "", $hCtrl, "{ENTER}")
$oIE.visible = False
_BlockInput ($BI_ENABLE)

Sleep (2000)
_IEQuit ($oIE)

You may need/try to adjust the sleep time...

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...