无法找到“getElementById”的重载和参数计数:“1” [英] Cannot find an overload for "getElementById" and the argument count: "1"
问题描述
我在一个简单的PowerShell脚本中遇到此错误。 getElementByID总是需要1个参数,所以我不确定为什么会失败。我正在使用在WS2K8 r2上运行的IE 11和PowerShell 3.
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()
产生错误信息:
找不到超载对于getElementById和参数计数:
1。在C:\ SCRIPTS \sample.ps1:5 char:1
+ $ ie.document.getElementById(search_form_input_homepage)。value =foobar
+ ~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~
+ CategoryInfo:NotSpecified:(:) [],MethodException
+ FullyQualifiedErrorId:MethodCountCouldNotFindBest
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
推荐答案
感谢SiZiIOUS的链接 - 最终导致我尝试测试空引用 - 似乎在从HTTP重定向到HTTPS至少某些部分COM对象丢失。
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".
将事物重置为默认值(包括Internet区域安全设置)后,看来我需要做的两件事就是没有以管理员身份运行PowerShell:
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:
- 禁用IE增强安全配置
- 将所需的URL添加到兼容性视图
另外值得注意的是 - 如果在此之后我将URL添加到可信站点,它实际上停止再次工作,我怀疑这使我在之前的某个时刻错过了解决方案尝试了可能在可信站点中列出的这些设置组合。为什么会这样,我不确定,但也许它会引发一个可以解释的人的想法。
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.
这篇关于无法找到“getElementById”的重载和参数计数:“1”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!