Jump to content

How to download file using AutoIT?


Recommended Posts

Referring to following coding, I would like to know on how to click Export button properly, I try following code without luck.

#include <IE.au3>
While ProcessExists("iexplore.exe")
    ProcessClose("iexplore.exe")
WEnd
Global $sFileSavePath = "C:\Download"  ;~ Folder Path to Save Excel Documents
Global $oIE = _IECreate("https://financials.morningstar.com/ratios/r.html?t=0P0001648D&culture=en&platform=sal")
Sleep(10000)     ;~ Wait while page loads
$oDivs = $oIE.Document.getElementByID('financials')
For $oDiv In $oDivs
    If $oDiv.className = "large_button" Then
        _IEAction($oDiv, "click")
        ExitLoop
    EndIf
Next

 

Do you have any suggestions?
Thank you very much for any suggestions (^v^)

 

 

Edited by oemript
Link to comment
Share on other sites

Looking from the source code of the webpage, you just have to call the javascript. Like this

#include <IE.au3>

While ProcessExists("iexplore.exe")
    ProcessClose("iexplore.exe")
WEnd

Global $sFileSavePath = "F:\Documents"  ;~ Folder Path to Save Excel Documents
Global $oIE = _IECreate("https://financials.morningstar.com/ratios/r.html?t=0P0001648D&culture=en&platform=sal")
_IENavigate($oIE, "javascript:exportKeyStat2CSV()")

This will open the save as popup. May be you can build from there.

Link to comment
Share on other sites

I would like to know on how to click save into default User's download or (specific folder "F:\documents" if possible) folder using AutoIT.

Save.png

Do you have any suggestions?

Thank you very much for any suggestions (^v^)

 

Edited by oemript
Link to comment
Share on other sites

A simple Google search will give you the way for that. Anyway here it goes

#include <IE.au3>

While ProcessExists("iexplore.exe")
    ProcessClose("iexplore.exe")
WEnd

Global $sFileSavePath = "F:\Documents"  ;~ Folder Path to Save Excel Documents
Global $oIE = _IECreate("https://financials.morningstar.com/ratios/r.html?t=0P0001648D&culture=en&platform=sal")
_IENavigate($oIE, "javascript:exportKeyStat2CSV()")

Local $hIE = WinGetHandle("[Class:IEFrame]")
Local $hCtrl = ControlGetHandle($hIE, "", "[ClassNN:DirectUIHWND1]")

WinActivate($hIE)

ControlSend($hIE ,"",$hCtrl,"{F6}")
ControlSend($hIE ,"",$hCtrl,"{TAB}")

; To Save to default folder
ControlSend($hIE ,"",$hCtrl,"{ENTER}")

; To open save as dialog box
;~ Sleep(500)
;~ Send("{DOWN 2}")
;~ Send("{ENTER}")
;~ WinWaitActive("Save As")
;~ Send($sFileSavePath & "\abc.csv")
;~ Send("{ENTER}")

 

Link to comment
Share on other sites

I would like to know on what wrong Case 2 is, that is not able to save into F:\Documents Folder, and save into User's Download Folder instead.

 

; Case 1
; Save to User's Download Folder with no problem
Send("{DOWN 1}")
Send("{ENTER}")

; Case 2
; Not able to save into F:\Documents Folder, and save into User's Download Folder instead
Send("{DOWN 2}")
Send("{ENTER}")
WinWaitActive("Save As")
Send($sFileSavePath & "\abc.csv")
Send($sFileSavePath & "\abc.csv")
Send("{ENTER}")

 

Do you have any suggestions?

Thank you very much for any suggestions (^v^)

 

Link to comment
Share on other sites

Based on the information provided in the above post, I can only say that including the sleep command, as in my post, may help. The sleep command has to be before the Send("{DOWN 2}" ) command. May be if I see the whole script, I can help you further.

Also, why do you have the Send($sFileSavePath & "\abc.csv") command twice?

Edited by siva1612
Link to comment
Share on other sites

It seems that can only save under last saved directory, and not able to change the saved filename as well.

Do you have any suggestions?
Thank you very much for any suggestions (^v^)

 

#include <IE.au3>
While ProcessExists("iexplore.exe")
    ProcessClose("iexplore.exe")
WEnd

Global $sFileSavePath = "F:\Documents"  ;~ Folder Path to Save Excel Documents
Global $oIE = _IECreate("https://financials.morningstar.com/ratios/r.html?t=0P0001648D&culture=en&platform=sal")
_IENavigate($oIE, "javascript:exportKeyStat2CSV()")

Local $hIE = WinGetHandle("[Class:IEFrame]")
Local $hCtrl = ControlGetHandle($hIE, "", "[ClassNN:DirectUIHWND1]")

WinActivate($hIE)

ControlSend($hIE ,"",$hCtrl,"{F6}")
ControlSend($hIE ,"",$hCtrl,"{TAB}")

; To Save to default folder
ControlSend($hIE ,"",$hCtrl,"{ENTER}")

; To open save as dialog box
Sleep(500)

Send("{DOWN 2}")
Send("{ENTER}")
WinWaitActive("Save As")
Send($sFileSavePath & "\abc.csv")
Send("{ENTER}")

 

Edited by oemript
Link to comment
Share on other sites

I had given two options in my script to indicate the different possibilities. If you wish to save to a directory other than the default, then the first options has to be commented out. Apologies if In wasn't clear. your code should be 

#include <IE.au3>
While ProcessExists("iexplore.exe")
    ProcessClose("iexplore.exe")
WEnd

Global $sFileSavePath = "F:\Documents"  ;~ Folder Path to Save Excel Documents
Global $oIE = _IECreate("https://financials.morningstar.com/ratios/r.html?t=0P0001648D&culture=en&platform=sal")
_IENavigate($oIE, "javascript:exportKeyStat2CSV()")

Local $hIE = WinGetHandle("[Class:IEFrame]")
Local $hCtrl = ControlGetHandle($hIE, "", "[ClassNN:DirectUIHWND1]")

WinActivate($hIE)

ControlSend($hIE ,"",$hCtrl,"{F6}")
ControlSend($hIE ,"",$hCtrl,"{TAB}")

; To open save as dialog box
Sleep(500)

Send("{DOWN 2}")
Send("{ENTER}")
WinWaitActive("Save As")
Send($sFileSavePath & "\abc.csv")
Send("{ENTER}")

 

Link to comment
Share on other sites

It seems that AutoIT cannot change last save directory on my PC, I would like to know on whether you can save under F:\Documents directory on your PC or not.  If it is the limitation of AutoIT, maybe it is OK to save under User's download folder.

6886c.png

Do you have any suggestions?
Thank you very much for any suggestions (^v^)

Edited by oemript
Link to comment
Share on other sites

It does not matter what is the default folder that appears on the Save As dialog box . As long you provide the entire file name with the full path in the filename textbox, it will work i.e. If you provide "F:/Documents/abc.csv" as the file name, even if the active folder in the dialog box is this "John" folder, the file will be saved in the correct location.

Link to comment
Share on other sites

I would like to know on why it pauses and pops up save as dialog box as shown on previous post, Do I need following statement?

WinWaitActive("Save As") = Pauses execution of the script until the requested window is active.

Do you have any suggestions?
Thank you very much for any suggestions (^v^)

 

Link to comment
Share on other sites

Referring to following image, I would like to know on how to retrieve the class name under id="star_span" into variable

Star.png

Do you have any suggestions?

Thanks, to everyone very much for any suggestions (^v^)

 

Edited by oemript
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...