A N

October 30, 2014

Send commands to IE from Powershell

Filed under: Tips — donrsh @ 11:24 am

The below code is just a sample code. Modify it…
It starts the IE, logging to “site” and doing some clicking.

$username="USERNAME"
$password="PASSWORD"
$ie = New-Object -com internetexplorer.application;
$ie.visible = $true;
$ie.navigate($Uri);
while ($ie.Busy -eq $true)
{
Start-Sleep -Milliseconds 1000;
}

$ie.Document.getElementById("user_name").value = $username
$ie.Document.getElementByID("password").value=$password
$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate('Internet Explorer')
$ie.Document.getElementByID("password").Focus()
Sleep 3
$wshell.SendKeys('~')
Start-Sleep -Milliseconds 1000
$link = @($ie.Document.getElementsByTagName('A')) | Where-Object {$_.innerText -eq 'select site'}
Sleep 3
$link.click()
sleep 3
$linkpage2 = @($ie.Document.getElementsByTagName('A')) | Where-Object {$_.innerText -eq 'Logoff'}
$linkpage2.click()
Sleep 5
Get-Process -Name iexplore | Stop-Process
Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: