Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
968 views
in Technique[技术] by (71.8m points)

internet explorer - Cannot find an overload for "getElementById" and the argument count: "1"

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:SCRIPTSsample.ps1:5 char:1 + $ie.document.getElementById("search_form_input_homepage").value = "foobar" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodCountCouldNotFindBest

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...