Resources to learn to use Powershell to automate IE functions

For the past several days I have been searching resources for how to use Powershell to automate IE functions.

We need to create powershell scripts to pass credentials into websites, to click on buttons on a webpage, to search for information and read it back into a powershell script, etc.

So far when I google Powershell IE automation, I only find few code examples, and I am struggling to get these examples to work.

My first question is, can you recommend good resources to learn and practice IE automation using powershell?

Second question is, I found code on technet, it looks correct, but I cannot understand why I'm getting so many errors:

$ie = new-object -com "InternetExplorer.Application"
$ie.visible = $true
$ie.navigate("http://www.gmail.com")
$doc = $ie.Document
$user = $doc.getElementByID("Email")
$user.value = "me@gmail.com"
$pass = $doc.getElementByID("Passwd")
$pass.value  = "my_password"
$Logon = $doc.getElementByID("signIn")
$Logon.click()

Please point me in the right direction.

EDIT:

Oh yes, and here are the errors

You cannot call a method on a null-valued expression.
At C:\sandbox\web2.ps1:10 char:28
+ $user = $doc.getElementByID <<<< ("Email")
    + CategoryInfo          : InvalidOperation: (getElementByID:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
Property 'value' cannot be found on this object; make sure it exists and is settable.
At C:\sandbox\web2.ps1:12 char:7
+ $user. <<<< value = "me@gmail.com"
    + CategoryInfo          : InvalidOperation: (value:String) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound
 
You cannot call a method on a null-valued expression.
At C:\sandbox\web2.ps1:14 char:28
+ $pass = $doc.getElementByID <<<< ("Passwd")
    + CategoryInfo          : InvalidOperation: (getElementByID:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
Property 'value' cannot be found on this object; make sure it exists and is settable.
At C:\sandbox\web2.ps1:16 char:7
+ $pass. <<<< value  = "my_password"
    + CategoryInfo          : InvalidOperation: (value:String) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound
 
You cannot call a method on a null-valued expression.
At C:\sandbox\web2.ps1:18 char:29
+ $Logon = $doc.getElementByID <<<< ("signIn")
    + CategoryInfo          : InvalidOperation: (getElementByID:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
You cannot call a method on a null-valued expression.
At C:\sandbox\web2.ps1:20 char:13
+ $Logon.click <<<< ()
    + CategoryInfo          : InvalidOperation: (click:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

  • Edited by Happy and Cheery Tuesday, August 27, 2013 1:57 PM Added the errors I am receiving
August 27th, 2013 1:46pm

function Test-GmailLogin{
     Param(
          $email,
          $passwd
     )

     $ie = New-Object -ComObject InternetExplorer.Application
     $ie.Visible = $true
     $ie.navigate('http://www.gmail.com')
     while($ie.Busy){sleep -mil 100}
     if($ie.Document.Url -match 'Inbox'){
          Write-Host 'Account already logged in' -ForegroundColor green -BackgroundColor white
          return $ie
     }else{
	     $ie.Document.getElementById("email").value=$email
	     $ie.Document.getElementByID("Passwd").value=$passwd
	     $ie.Document.getElementById("signin").Click()
	     while($ie.Busy){sleep -mil 100}
	     if($ie.Document.Url -match 'Inbox'){
	     	Write-Host 'Successfull login!' -fore green
	     	return $ie
	     }else{
	     	Write-Host 'Login failed!' -ForegroundColor red
	     }
	}
}

$ie=Test-GmailLogin -email johnsmith@gmail.com -pass zippiedoodah

Free Windows Admin Tool Kit Click here and download it now
August 27th, 2013 1:54pm

Thank you!

This code works really well ~~~ this is a great starting point to learn this awesome stuff!

August 27th, 2013 2:16pm

i am getting the below error message please help me out of this

Property 'value' cannot be found on this object; make sure it exists and is settable.
At line:16 char:48
+          $ie.Document.getElementByID("Passwd"). <<<< value=$passwd
    + CategoryInfo          : InvalidOperation: (value:String) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

Login failed!

Free Windows Admin Tool Kit Click here and download it now
August 12th, 2015 1:34pm

i am getting the below error message please help me out of this

Property 'value' cannot be found on this object; make sure it exists and is settable.
At line:16 char:48
+          $ie.Document.getElementByID("Passwd"). <<<< value=$passwd
    + CategoryInfo          : InvalidOperation: (value:String) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

Login failed!
August 12th, 2015 1:35pm

Please start your own topic as this one is and has been closed.

Free Windows Admin Tool Kit Click here and download it now
August 12th, 2015 1:42pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics