1

I have the following PowerShell code that works fine on a machine with PowerShell 2.0 and IE 8, but does not work on a separate machine with IE 10.

$ie = new-object -com "InternetExplorer.Application"
$ie.visible=$true
$ie.Navigate("http://localhost/website/")
While ($ie.busy) {Sleep 2}
$doc = $ie.document
$autobutton = $doc.getElementById("IdName").Click()

The HTML code I'm attempting to access looks something like this:

<input type="radio" id="IdName" checked value="true" />

And here is the error I'm getting when running the PowerShell code above on the machine with IE 10:

"You cannot call a method on a null-valued expression."

Does IE 10 not support getElementById? Do I need modify my script to handle IE 10 differently so that the button gets clicked?

NOTE: the server with IE 10 also has PowerShell 3, and so I've tried using Invoke-WebRequest as well, but that doesn't seem to help either (get same error).

Thanks in advance!

Keith
  • 1,959
  • 10
  • 35
  • 46
  • Works for me on Win7 SP1 with IE10 and PowerShell V3. I can find elements by ID using getElementByID(). However Click() is a method. Does it return anything? You may be getting null assigned to $autobutton. Did you want the Click function instead e.g. `$autobutton = $doc.getElementById("IdName").Click`? – Keith Hill Nov 05 '13 at 21:57
  • I still get the same error using the Click function or even without the Click. And not sure if it matters but the machine is Server 2008 R2 SP1. – Keith Nov 05 '13 at 22:03
  • Which specific line of code is giving that error? If it is that last line, then are you sure $doc isn't null? – Keith Hill Nov 05 '13 at 22:12
  • Hmm...$doc is returning null if I use Invoke-WebRequest, but does not return null if I use new-object -com "InternetExplorer.Application" and $ie.Navigate. Either way I still get the same error above. And the line of code throwing the error is the last line: $autobutton = $doc.getElementById("IdName").Click – Keith Nov 05 '13 at 22:32
  • Ack! I think I found the problem: http://stackoverflow.com/questions/6065359/powershell-ie9-and-getelementbyid?rq=1. Anyway, I think I'm good to go now after making the settings changes in IE. – Keith Nov 05 '13 at 23:17

0 Answers0