Reputation: 83
Am in process of automating the daily download of a zip file from secure site. Script is ready which uses the internet explorer to login and go to the required location and then click on download button, script works as expected till here.
Upon clicking download button, it prompts to click on save button. Have tried with send keys with below
$wshell = New-Object -ComObject WScript.Shell
$id = (gps iex* | where {$_.MainWindowTitle -match "Title"}).id
$wshell.AppActivate($id)
start-sleep 1
$wshell.SendKeys("%{n}")
Start-Sleep 1
want to send keys (Alt+n + TAB + ENTER), tried by changing few things but end up with the same result.
Upvotes: 8
Views: 42685
Reputation: 3236
To emulate send keys you want to use System.Windows.Forms.SendKeys
class.
The plus sign (+), caret (^), percent sign (%), tilde (~), and parentheses () have special meanings to SendKeys. To specify one of these characters, enclose it within braces ({})
In your case, according to documentation, code sample should look like:
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.SendKeys]::SendWait("%n{TAB}{ENTER}")
Where:
%
stands for ALT
button;n
stands for n
button;{TAB}
stands for TAB
button;{ENTER}
stands for ENTER
button.Please follow the documentation page to can see complete list of available options here.
Upvotes: 11