0
votes

I'm getting this error in a simple PowerShell script. "getElementByID" always takes 1 argument, so I'm not sure why this is failing. I'm using IE 11 and PowerShell 3 running on WS2K8 r2.

$ie = New-Object -com InternetExplorer.Application 
$ie.visible=$true
$ie.navigate("http://duckduckgo.com") 
while($ie.ReadyState -ne 4) {start-sleep -m 100}
$ie.document.getElementById("search_form_input_homepage").value = "foobar"
$ie.document.getElementById("search_button_homepage").Click()

resulting error message:

Cannot find an overload for "getElementById" and the argument count: "1". At C:\SCRIPTS\sample.ps1:5 char:1 + $ie.document.getElementById("search_form_input_homepage").value = "foobar" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodCountCouldNotFindBest

1
Your code works under IE 11 and Windows 7 x64. So maybe it's a security issue?SiZiOUS
good suggestion - I tried disabling IE Enhanced Security Configuration for Admins and Users both, but no luck. maybe there's something else security-related I could try?msulis
so far I've tried cumulatively (1) disabling IE ESC (2) disabling protected mode for the Internet Zone (3) running powershell as administrator - all to no avail.msulis

1 Answers

2
votes

Thanks SiZiIOUS for the link - eventually that led me to try testing for null references - it seems that during the redirect from HTTP to HTTPS at least some part of the COM object is "lost".

After resetting things back to defaults (including Internet Zone security settings), it appears that the two things I need to do to get this to work without running PowerShell as administrator are:

  1. Disable IE Enhanced Security Configuration
  2. Add the desired URL to Compatibility View

Also worth noting - if after this I add the URL to Trusted Sites, it actually stops working again, which I suspect caused me to miss the solution at some point previously since when I tried this combination of settings it was probably listed in Trusted Sites. Why that would be, I'm not sure, but maybe it will spark a thought for someone who can explain.