Powershell 网站登录无效 [英] Powershell website login not working
问题描述
我正在尝试编写一个基本的 powershell 脚本来登录 gmail,但遇到了一些问题.代码如下.我已经注释掉了一些内容以缩小范围.
I am trying to write a basic powershell script to log into gmail but have some up against a problem. The code is below. I have commented out some bits to narrow things down.
$url = "http://gmail.com"
$username="myusername"
$password= "123456"
$ie = New-Object -com InternetExplorer.Application
$ie.visible = $true;
$ie.navigate($url);
while ($ie.Busy)
{
Start-Sleep -m 10000;
}
$counter = 0
while (($counter -lt 10) -and ($ie.document -eq $null)) {Start-Sleep 1; $counter++}
$ie.document -eq $null
$ie.Document.getElementByID('email').value=$username
#$ie.Document.getElementByID("Password").value=$password
#$ie.Document.getElementById("signin").Click();
当我运行 powershell 脚本时,出现以下错误.
When I run the powershell script, I get the following error.
You cannot call a method on a null-valued expression.
At J:\scripts\gmail.ps1:21 char:1
+ $ie.Document.getElementByID('email').value=$username
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
奇怪的是,昨天它运行得很好,今天它根本不起作用.我使用的是 IE9.
The strange thing is, this was working perfectly fine yesterday and today its not working at all. I am using IE9.
非常感谢任何帮助.
推荐答案
PowerShell IE9 ComObject 在导航到网页后具有所有 null 属性 给了我答案.由于 IE 保护模式阻止了对象的创建,我不得不以管理员身份运行我的脚本.关闭 IE 保护模式或以管理员身份运行脚本以使其正常工作.
PowerShell IE9 ComObject has all null properties after navigating to webpage gave me the answer to this. Had to run my script as an administrator due to IE protected mode that was stopping the object from being created. Either turn off IE protected mode or run the script as an administrator to get it working.
这篇关于Powershell 网站登录无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!