File download/save notification bar in IE 11

Started by hdsouza, April 05, 2014, 01:53:16 PM

Previous topic - Next topic

hdsouza

In IE 8 if you had to download a file you would get the window "File Save" . Here you could do a sendkeys to the window and save the file
In IE9 onwards there is notification bar that comes up which does not have a window name.
Hence how do I automatically do a "Save as" with sendkey or otherwise when the Download notification bar comes up
By Notification Bar I am referring to the Gold-White bar that appears on the page when one tries to download a file

I have tried using roboscripter to uncover the guts of the download notification bar, but it does not show much and at least does not uncover the Open, Save , Cancel buttons. i have tried using cGetSBText and other similar commands but no luck

Please help

Deana

Have you considered downloading the file directly using Wininet/WinSock or WinHTTP, rather than trying to drive the IE User Interface? There are a few different ways to accomplish this in WinBatch. Here is a code sample that shows 3 of the ways: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/How~To+Various~Ways~to~Download~a~File.txt
Deana F.
Technical Support
Wilson WindowWare Inc.

hdsouza

Deana,  If i have to use the script on the help site then I have to login to the site first
I have tried WinInet and Winsock (see scripts below) but I am not able to login
Even If I were to be able to login, it will be complex to navigate the site using WinInet/Winsock as there are drop down lists that need to be selected to generate the download. Thats the reason why I wanted to get the download from the Notification bar

Anyway here is my two versions of scripts I am trying to get to login to the site
Please help

; Script to verify login to site
AddExtender("wwwsk44i.dll")
AddExtender("wwint44i.dll")
EODData_Login =  "ezmail1968@gmail.com"
EODData_Password = "password"
URL ="http://www.eoddata.com"
Download_URL="http://www.eoddata.com/data/filedownload.aspx?e=INDEX&sd=20140404&ed=20140404&d=2&k=yvpx47fhcu&o=d&ea=1&p=0"
File = "c:\temp\eoddata.txt"
FileDelete(File)

;GoSub WinInet_Method
GoSub WinSock_Method
Exit

:WinInet_Method
tophandle=iBegin(0,"","")
conhandle=iHostConnect(tophandle,"www.eoddata.com",@HTTP, EODData_Login, EODData_Password)
;conhandle=iHostConnect(tophandle,"www.eoddata.com",@HTTPs, EODData_Login, EODData_Password)
datahandle=iHttpInit(conhandle, "GET", "/", "",0)
If datahandle==0
   err=iGetLastError()
   Message("Last Error",err)
   iClose(tophandle)
   Exit
EndIf
rslt=iHttpOpen(datahandle, "", 0, 0)
iReadData(datahandle,File)
iClose(datahandle)
iClose(tophandle)
Return

:WinSock_Method
httpAuth(EODData_Login,EODData_Password)
Serv = httpGetServer(URL,"")
path=httpGetPath(URL, "")
httpRecvFile(Serv,Path,File,0)
Return

hdsouza

If login does not work then how would I be able to get the co-ordinates/controls of the notification bar

AddExtender("wwctl44i.dll")
IE_WinName = '~- Internet Explorer'
window1=DllHwnd(IE_WinName)
window2=cWndByClass(window1,`Frame Notification Bar`)
ControlHandle=cWndByClass(window2,`DirectUIHWND`)

hdsouza

Here is the same thing done with autoit - sending keys to the save - as button
http://www.autoitscript.com/forum/topic/127987-handling-ie9-file-download-activex-prompts/
I am thinking that winbatch is more superior and the same thing can be done here

Anyone have any ideas?
(the code is similar as in my previous message)

Deana

Quote from: hdsouza on April 07, 2014, 07:52:47 AM
Here is the same thing done with autoit - sending keys to the save - as button
http://www.autoitscript.com/forum/topic/127987-handling-ie9-file-download-activex-prompts/
I am thinking that winbatch is more superior and the same thing can be done here

Anyone have any ideas?
(the code is similar as in my previous message)

It appears that code was designed for IE9 and you are working with IE 11. I suspect things have changed a bit. Do you have Windows Analysis output of the "window" you are trying to work with?
Deana F.
Technical Support
Wilson WindowWare Inc.

hdsouza

How do you generate a "windows anylysis output"?

All I am asking is "How do you get the co-ordinates of the IE notification bar".

And its not like I have not written any code, I have written most of the code for it. Yes its always been IE 11 (See title)

Deana

Deana F.
Technical Support
Wilson WindowWare Inc.

Deana

Here is a code sample that I just threw together that might help:

Code (winbatch) Select
ShellExecute('http://www.tucows.com/thankyou.html?swid=996415', '', '', @NORMAL, '')
title = "~Thank you for downloading"
WinWaitExist(title, 10)
AddExtender("wwctl44i.dll")
window1=DllHwnd('Thank you for downloading Easy screen capture software for Windows 7 - Tucows Downloads - Internet Explorer')
FNB = cFindByClass(`Frame Notification Bar`)
winid = cWinIDConvert(FNB)
pos = WinPosition( winid )
ulc = MouseMove( ItemExtract(1,pos,","), ItemExtract(2,pos,","), title, '' )
exit
Deana F.
Technical Support
Wilson WindowWare Inc.

Deana

Deana F.
Technical Support
Wilson WindowWare Inc.

hdsouza

Thanks for the script. Unfortunately the cordinates returned by the script do not exactly match the Notification bar. I moved the browser to one side but still on the visible screen and ran the script again. it retuns codes and positions the mouse outside the screen. Other times it positions the mouse at the center of the notification bar. This will make it impossible to position the mouse and click on the "save as" button. I realise I could do a winplace of the browser , but the next problem is screen resolution and the place to click to get to the "save as" options is a hairline

If the controls of the notification bar cannpot be exposed with winbatch  then we  may have to go back to trying to login to the site and download with winbatch. I tried WinInet and Winsocks and both fail (see scripts above).

Deana

Quote from: hdsouza on April 07, 2014, 03:13:14 PM
Thanks for the script. Unfortunately the cordinates returned by the script do not exactly match the Notification bar. I moved the browser to one side but still on the visible screen and ran the script again. it retuns codes and positions the mouse outside the screen. Other times it positions the mouse at the center of the notification bar. This will make it impossible to position the mouse and click on the "save as" button. I realise I could do a winplace of the browser , but the next problem is screen resolution and the place to click to get to the "save as" options is a hairline

If the controls of the notification bar cannpot be exposed with winbatch  then we  may have to go back to trying to login to the site and download with winbatch. I tried WinInet and Winsocks and both fail (see scripts above).

Yes when you start working with Mouse operations you will need to deal with window placement and screen resolution.

Okay so you state that the WinInet and WinSock codes fails. Please provide details. I recommend using DebugTrace. Simply add DebugTrace(@on,"trace.txt") to the beginning of the script and inside any UDF, run it until the error or completion, then inspect the resulting trace file for clues as to the problem.

Feel free to post the trace file here ( removing any private info) if you need further assistance.

Deana F.
Technical Support
Wilson WindowWare Inc.

hdsouza

Here are the scripts to login. At the end of the scrpit I download the webpage (eoddata.txt) to find if the webpage has logged in. I am expecting to see the account page but it shows still shows the login page. I have created a login/password just for this testing. With Wininet I also tried https and that does not get through too.

; Script to verify login to site
AddExtender("wwwsk44i.dll")
AddExtender("wwint44i.dll")
DebugTrace(@on, "c:\temp\trace.txt")
EODData_Login =  "ezmail1968@gmail.com"
EODData_Password = "password"
URL ="http://www.eoddata.com"
File = "c:\temp\eoddata.txt"
FileDelete(File)

;GoSub WinInet_Method
GoSub WinSock_Method
Exit

:WinInet_Method
tophandle=iBegin(0,"","")
conhandle=iHostConnect(tophandle,"www.eoddata.com",@HTTP, EODData_Login, EODData_Password)
;conhandle=iHostConnect(tophandle,"www.eoddata.com",@HTTPs, EODData_Login, EODData_Password)
datahandle=iHttpInit(conhandle, "GET", "/", "",0)
If datahandle==0
   err=iGetLastError()
   Message("Last Error",err)
   iClose(tophandle)
   Exit
EndIf
rslt=iHttpOpen(datahandle, "", 0, 0)
iReadData(datahandle,File)
iClose(datahandle)
iClose(tophandle)
Return

:WinSock_Method
httpAuth(EODData_Login,EODData_Password)
Serv = httpGetServer(URL,"")
path=httpGetPath(URL, "")
httpRecvFile(Serv,Path,File,0)
Return

Deana

I was going to suggest using WinInet http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+Tutorials+HTTP~and~WinInet~-~An~Opus.txt

However it appears that website is storing information in the Page's ViewState Property which complicates matters:

http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WIL~Extenders/WinInet+Website~Forms~with~Viewstate~and~Eventvalidation~.txt

http://msdn.microsoft.com/en-us/library/ms972976.aspx

I suspect you will need to query the host to obtain the ViewState value and include it in your HTTP POST.

Unfortunately we don't have any prewritten code samples to handle webpages containing a ViewState. Maybe someone else has a code sample they are willing to share...

Anyone?



Deana F.
Technical Support
Wilson WindowWare Inc.

Deana

It appears EODData Web Service at this url: http://ws.eoddata.com/data.asmx.

It appears you need to be a platinum member to use the service.

Here is a SOAP tutorial for WinBatch:
http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/XML+SOAP.txt
Deana F.
Technical Support
Wilson WindowWare Inc.

Deana

Okay, since the site uses VIEWSTATE I figured you would be best off using COM automation of MSIE. Here is a code sample I came up with:

Code (winbatch) Select
;***************************************************************************
;**                  EODDATA Auto-Login Simple
;**             Logs into your EODDATA account online.
;**
;** Developer: Deana Falk 2014.04.08                 
;***************************************************************************

;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
; Ensure that you are signed-out of EODDATA before running
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

EODData_Login =  "soandso@tld.com" ; MODIFY TO FIT YOUR NEEDS
EODData_Password = "password"                 ; MODIFY TO FIT YOUR NEEDS
filename = "c:\temp\eoddata.txt"
FileDelete(filename)


oIE = ObjectCreate('internetexplorer.application')
oIE.visible = @true;
oIE.navigate(url);
while oIE.Busy 
    TimeDelay(1)
endwhile

; Wait for element
;While @true
   oElement = oIE.Document.getElementById("ctl00_cph1_lg1_txtEmail")
;   type = ObjectTypeGet(obj)
;   if type != 'NULL' then break
;EndWhile
oElement.value = EODData_Login


; Wait for element
;While @true
   oElement = oIE.Document.getElementById("ctl00_cph1_lg1_txtPassword")
;   type = ObjectTypeGet(obj)
;   if type != 'NULL' then break
;EndWhile
oElement.value = EODData_Password

; Wait for element
;While @true
   oElement = oIE.Document.getElementById("ctl00_cph1_lg1_btnLogin")
;   type = ObjectTypeGet(obj)
;   if type != 'NULL' then break
;EndWhile

; Click button
;oElement.Click             
;or
; Click button on IE 9 and newer
; createEvent initEvent DispatchEvent
oEvent = oIE.Document.createEvent("HTMLEvents")
oEvent.initEvent("click", @TRUE, @TRUE)
oElement.dispatchEvent(oEvent)
oEvent = 0

while oIE.Busy 
    TimeDelay(1)
endwhile

data = oIE.document.body.innerHTML
data2 = oIE.document.body.outerHTML
data3 = oIE.document.body.innerText
data4 = oIE.document.body.outerText
FilePut( filename, data3 )

ShellExecute( filename, '', '', @NORMAL, '')

oElement = 0
oIE = 0
Exit
Deana F.
Technical Support
Wilson WindowWare Inc.

hdsouza

Deana, Thanks for the code. I have already been using an almost similar  process to get to login to the site. It works great on IE 8. On IE 11 I end up with the initial problem ...which is How to download the file. Also this file is not a static file , but is generated from a selection of menus.

msie = ObjectOpen("InternetExplorer.Application")
msie.Visible = @True
msie.Navigate("http://eoddata.com/")
TIMEDELAY(0.3)
; wait for page to open.. script not shown here

msie.document.GetElementByid("ctl00_cph1_lg1_txtEmail").value = EODData_Login
msie.document.GetElementByid("ctl00_cph1_lg1_txtPassword").value = EODData_Password
msie.document.GetElementByid("ctl00_cph1_lg1_btnLogin").click
; check if page is logged in .. script not shown here

msie.Navigate("http://eoddata.com/download.aspx") ; navigate to dowload section
; wait for page to load .. script not shown here

MySelect_Exchange= msie.document.getElementsByTagName("select").item(0) ; select the exchange
Select_ExchangePos = 20 ; Nasdaq
MySelect_Exchange.Options.item(%Select_ExchangePos%).selected = @TRUE ; set the exchange
MySelect_Format= msie.document.getElementsByTagName("select").item(1) ; Set the format
Select_FormatPos = 1
MySelect_Format.Options.item(%Select_FormatPos%).selected = @TRUE
msie.document.GetElementByid("ctl00_cph1_d1_chkAllSymbols").checked = 1
msie.document.GetElementByid("ctl00_cph1_d1_chkAllSymbols").fireevent("onclick")

; At this stage we have a link to the file to be downloaded. If we click the link We get hit with the IE notification bar
LinksCollection = msie.document.links
ForEach link In LinksCollection
   Link_Href = strtrim(link.href)
   DownloadLink_Exist =  StrIndexNC(Link_Href, "/filedownload.aspx?e", 1, @FWDSCAN)
   if DownloadLink_Exist == 0 then Continue
   link.click
   Break
Next

At this stage I get the IE Notification bar to download the file which is the source of my problem. Hence Instead of clicking the link is there another way to download the file




Deana

Okay looks like your stuck with mouse operations or paying eoddata for the service. Looks like they have a nice FTP service that can easily be automated in WinBatch: http://eoddata.com/products/Services.aspx
Deana F.
Technical Support
Wilson WindowWare Inc.

hdsouza

Quote from: Deana on April 07, 2014, 01:41:38 PM
Posted to the tech database for the next user: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WIL~Extenders/Control~Manager+Locate~the~IE~Download~Notification~Bar.txt

I managed to write an alternate script without mouse move. An Alt-N could work as well although at times the window is hidden, hence getting the ID to start with makes the process precise. Tested various websites and works evertime ..... so far. Maybe you could validate and post to the database is needed

Code (winbatch) Select


AddExtender("wwctl44i.dll")
App_Log = "c:\Temp\App_Log.txt"
FileDelete(App_Log)
DebugTrace(@on,App_Log)
File_Var = "c:\temp\download.txt"
;IE_Name = "~Download Stock Data and Historical"
WinID_list = WinItemNameId( )
WinID_list= StrReplace(WinID_list, "|#", @TAB)
WinID_list= StrReplace(WinID_list, "WIN$ID", "#WIN$ID")
WinCount=ItemCount(WinID_list,"|")
for xx=1 to WinCount
    ThisWin=ItemExtract(xx,WinID_list,"|")
    Win_Name = strtrim(itemextract(1, ThisWin, @tab))
    Win_Id = strtrim(itemextract(2, ThisWin, @tab))
    if winexist(Win_Id)!=@true then continue ; if window was closed by another process
    WindowExist1 = StrIndex(Win_Name, "- Internet Explorer", 1, @FWDSCAN)
    if WindowExist1 == 0 then continue
    win_state = WinState (Win_Id)
    ;Message ("win state", "Win_Name = %Win_Name%   win_state = %win_state%")
    if win_state != 2 then continue
    Break
Next

:Get_WinHandle
window1=DllHwnd(Win_Id)
if window1 == 0 then Goto Get_WinHandle
window2=cWndByClass(window1,`Frame Notification Bar`)
if window2 == 0 then Goto Get_WinHandle
ControlHandle=cWndByClass(window2,`DirectUIHWND`)
if ControlHandle == 0 then Goto Get_WinHandle
cSetFocus(ControlHandle)  ; Activates Window

Count_IndexDownload = 0
:SubCheck_IndexDwnld
Count_IndexDownload = Count_IndexDownload + 1
if Count_IndexDownload > 50 then return
; goes into an indefinite loop at this stage..
; if it happenes again.. setup a counter to break ot of the loop
timedelay(0.2)
if winexist("~View Downloads") != @true then goto SubCheck_IndexDwnld
WINACTIVATE("~View Downloads")

TIMEDELAY(2)
sendkeysto(Win_Id, "!N")
;exit
TIMEDELAY(2)
WINACTIVATE(Win_Id)
TIMEDELAY(2)
sendkeysto(Win_Id, "{TAB}")
TIMEDELAY(2)
;exit
sendkeysto(Win_Id, "{DOWN}")
TIMEDELAY(2)
sendkeysto(Win_Id, "{DOWN}")
TIMEDELAY(2)
sendkeysto(Win_Id, "~")
TIMEDELAY(2)
exit



Deana

Thanks for sharing the solution that works for you. if you truly want to send just ALt and 'n' then make sure you use a lowercase n. If you specify uppercase that gets interpreted as a SHIFT+n.
Deana F.
Technical Support
Wilson WindowWare Inc.

hdsouza