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