【发布时间】:2012-12-01 21:55:50
【问题描述】:
我有一个 PowerShell 脚本,它导航到我们 Intranet 上的(大概)经典 ASP 页面,以停止在我们的服务器上运行的 Windows 服务,作为该服务部署过程的一部分(并在部署新文件后重新启动它)。它运行良好,直到我们最近升级到 IE9。这是脚本。
# Open service page in IE
$ie = new-object -comobject InternetExplorer.Application
$ie.visible = $true
$ie.navigate($serviceUrl)
while($ie.busy) { start-sleep 1 }
# Stop service
$ie.Document.getElementById("dropDownActionList").value = "Stop"
$ie.Document.getElementById("buttonTakeAction").click()
while($ie.busy) { start-sleep 1 }
现在当我运行脚本时,它成功启动了 IE,但抛出以下错误:
You cannot call a method on a null-valued expression.
At C:\Projects\ABC\Scripts\Deploy.ps1:85 char:28
+ $ie.Document.getElementById <<<< ("dropDownActionList").value = "Stop"
+ CategoryInfo : InvalidOperation: (getElementById:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
当我在 PowerShell 中进行调查时,我发现如果我创建 IE ComObject,它首先具有有效的属性,但是一旦我导航到服务控制页面,所有属性都是空的(几乎就像 ComObject走了?)。例如,之前HWND 属性具有有效值,但现在它为空($ie.hwnd -eq $null 返回 true)。当我导航到该页面时,PowerShell 中没有显示错误。
我看了一些similarquestions,但第一个不符合我的情况(Document属性在我的情况下为空),至于后一个,IE9默认为内网兼容模式网站。我保存了 ASP 页面并通过w3c validator 运行它,它抛出了一些错误(尽管与我要处理的元素无关)。不幸的是,我无法解决这些问题。其他网站似乎没有这个问题。对问题可能是什么有任何怀疑以及解决方法的建议?
【问题讨论】:
标签: powershell internet-explorer-9