Powershell:无法在空值表达式错误上调用方法

时间:2013-06-11 15:21:09

标签: html internet-explorer powershell form-submit powershell-v3.0

我正试图通过powershell登录网站。

这是PS代码

$username = "userhere" 
$password = "passhere"
$ie = New-Object -com InternetExplorer.Application
$ie.visible=$false
$ie.navigate("http://www.desistream.tv/en/login.shtml")
while($ie.ReadyState -ne 4) {start-sleep -m 100}
$ie.document.getElementById("username").value= "$username"
$ie.document.getElementById("pass").value = "$password"
$ie.document.getElementById("loginform").submit()
start-sleep 20
$ie.Document.body | Out-File -FilePath c:\web.txt

这是我运行脚本时遇到的错误。

PS C:\Users\myname\Desktop> .\new.ps1
You cannot call a method on a null-valued expression.
At C:\Users\myname\Desktop\new.ps1:9 char:1
+ $ie.document.getElementById("loginform").submit()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

PS C:\Users\myname\Desktop> http://www.desistream.tv/en/index.shtml

1 个答案:

答案 0 :(得分:1)

该页面没有ID为“loginform”的元素。