我可以使用这个简单的脚本(或根据 ID 略有不同)登录 facebook、google 或 stackoverflow。但是,我的公司有一个网站,我无法使用 powershell 登录该网站。
$ie = New-Object -com InternetExplorer.Application
$ie.visible=$true
$ie.navigate("www.loginpage.com")
start-sleep 1;
# I was using this before, but it would never leave the loop...
# while($ie.ReadyState -ne 4) {start-sleep -m 100}
$ie.document.getElementById("username").value = "username"
$ie.document.getElementById("password").value = "password"
$ie.document.getElementById("loginform").submit()
我认为唯一的区别是该网站位于我们的“内联网”上,而不是互联网上,并且出于某种原因 powershell 区分了两者。但我不确定,我仍然可以正常打开 IE 并转到 url 并查看源代码并查看标签 ID 等。
有谁知道为什么在这种情况下使用 $ie.document.getElementById
时出现以下错误。
You cannot call a method on a null-valued expression.
+ CategoryInfo : InvalidOperation: (getElementById:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
我知道标签是:
<input name="username" id="username" langcode="EN" type="text">
<input name="password" id="password" type="password">
有什么想法吗?
最佳答案
解决方案是以管理员身份运行 PowerShell。这个答案有帮助: https://stackoverflow.com/a/14616609/347303
关于javascript - 通过powershell登录内部网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25534281/