Download file from web page button click using PowerShell

Viewed 463

I have a web page where there is a button called "Download Excel" - once we click on this button, this will download the excel. This is working fine from the web page UI, the same functionality we want to automate, so we are trying to achieve through powershell using the below code :

$ie = New-Object -comobject InternetExplorer.Application 
$ie.visible = $true
$ie.silent = $true
$ie.Navigate($loginUrl)
while($ie.busy){Start-Sleep 1} 


$copyBtn = $ie.Document.getElementsByClassName('btn btn-primary') | Where-Object {$_.innerText -eq 'Download Excel'} 
$copyBtn.click()

 

Download excel file from a web page

This is working fine - and opening the save as dialog box but I want to skip the save as dialog box or we should be able to pass the file download path and click OK button through the code (the file should be saved in pre-defined location)...Is it possible to achieve thru the PowerShell? If yes, how can I do this? PowerShell Expert opinions are appreciated :-)

0 Answers
Related