'PowerShell script to download from Web

I am trying to log on web page using PowerShell and generate some. Although Powershell ISE gives some errors, current script works okay(sometimes log on sometimes not) but last part seem doesn't work to generate the Report by clicking the "CSV" Button.

Any help please?

$username = "username" 
$password = "password" 
$ie = New-Object -ComObject InternetExplorer.Application 
$ie.visible=$true
$ie.navigate("http://..../login") 
while($ie.ReadyState -ne 4) {start-sleep -m 300} 
$ie.document.IHTMLDocument3_getElementById('user_session_email').Value=$username 
$ie.document.IHTMLDocument3_getElementById('user_session_password').Value=$password
$ie.Document.IHTMLDocument3_getElementById('commit').Click()
$ie.navigate("http://..../activity_reports") 
while($ie.ReadyState -ne 4) {start-sleep -m 100} 
$currentDate= (Get-Date).ToString('dd-MM-yyyy')
$ie.document.IHTMLDocument3_getElementById('from_date').innertext= $currentDate
$ie.document.IHTMLDocument3_getElementById('to_date').Value=$currentDate
$Link=$ie.Document.IHTMLDocument3_getElementByType('submit') | where-object {$_.class -eq 'btn 
btn-default btn-sm'}
$Link.click()

enter image description here

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source