Jump to content

IE Automation - Save file as


Go to solution Solved by 13lack13lade,

Recommended Posts

Posted

Hey all,

so i'm automating IE at the moment and i have a script that logs into a website and clicks a button to download a csv file however i can't figure out how to make it so it automatically saves the file in a specific location.

I tried InetGet but i think because it is signed into an account it doesn't work.

Any ideas?

Posted

do you try this:

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Solution
Posted (edited)

Bam - not pretty but i found the solution thanks to this post here : 

$hIE = WinGetHandle("[Class:IEFrame]")
$hCtrl = ControlGetHandle($hIE,"","[Class:DirectUIHWND]")
$aPos = ControlGetPos($hIE,"",$hCtrl)
$x = $aPos[2]-160
$y = $aPos[3]-30

;Use
WinActivate($hIE) ;doesn't work in the background
ControlClick($hIE,"",$hCtrl,"primary",1,$x,$y) ;this only gives focus to the save button
ControlSend($hIE,"",$hCtrl,"{down}") ;this does work once the save button is focussed
ControlSend($hie, "", "[Class:DirectUIHWND]","a") ;open save as dialog
Edited by 13lack13lade
Posted (edited)

Made it easier for people to understand how to edit this code to make it usable for them.

#include <IE.au3>

;open survey ie link
Local $oIE = _IECreate(url) ;change url to your specific url
Local $dCSV = _IEGetObjById($oIE,objIDname) ;find obj id to click on specific to your page
_IEAction ($dCSV,"click") ;click object e.g download button
sleep(1000)

;focus download dialog - dont need to change any of this
$hIE = WinGetHandle("[Class:IEFrame]")
$hCtrl = ControlGetHandle($hIE,"","[Class:DirectUIHWND]")
$aPos = ControlGetPos($hIE,"",$hCtrl)
$x = $aPos[2]-160
$y = $aPos[3]-30

;Use - dont need to change any of this
WinActivate($hIE) ;doesn't work in the background
ControlClick($hIE,"",$hCtrl,"primary",1,$x,$y) ;this only gives focus to the save button
ControlSend($hIE,"",$hCtrl,"{down}") ;this does work once the save button is focussed
ControlSend($hie, "", "[Class:DirectUIHWND]","a")

;save as - Dont need to change any of this except for filepath.
WinActivate("Save As", "Save");
WinWaitActive("Save As", "Save", 10);
ControlSetText("Save As", "", "Edit1", filepath);
ControlClick("Save As", "", "&Save", "left", 1, 5, 5);
sleep(100)
ControlClick("Confirm Save As","","Button1", "left", 1, 0, 0);

;quit ie
_IEQuit($oIE)
Edited by 13lack13lade

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
  • Recently Browsing   0 members

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