【问题标题】:"Unspecified Error" when calling getElementById()调用 getElementById() 时出现“未指定的错误”
【发布时间】:2016-01-25 06:59:57
【问题描述】:

执行以下脚本时出现此错误。还提到了相同的输出。我确实检查了错误,但没有找到任何修复方法。我正在使用带有 PowerShell 版本的 Windows 10:5.0.10586.0。请求任何人帮助解决此错误。我只能看到带有上述 URL 和可执行文件记事本的 IE 打开。脚本无法执行自动登录。

输出:

PS C:\WINDOWS\system32> C:\Users\admin\Desktop\Test.ps1
未指定的错误。
在 C:\Users\admin\Desktop\Test.ps1:35 char:1
+ $IE.Document.getElementById(“电子邮件”).value = $Username
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId:System.Runtime.InteropServices.COMException

未指定的错误。
在 C:\Users\admin\Desktop\Test.ps1:36 char:1
+ $IE.Document.getElementById(“signIn”).Click()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId:System.Runtime.InteropServices.COMException

未指定的错误。
在 C:\Users\admin\Desktop\Test.ps1:37 char:1
+ $IE.Document.getElementByID(“密码”).value=$Password
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId:System.Runtime.InteropServices.COMException

未指定的错误。
在 C:\Users\admin\Desktop\Test.ps1:38 char:1
+ $IE.Document.getElementById(“signIn”).Click()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

脚本:

# Edit this to be the URL or IP address of the site to launch on login
$Url = "www.gmail.com"

# Edit this to be the username
$Username= "xxxx@gmail.com"

# Edit this to the corresponding password
$Password= "xxxxx"

# Edit this to be the path to the executable.  Include the executable 
# file name as well.
$Executable = "c:\windows\system32\notepad.exe"

# Invoke Internet Explorer
$IE = New-Object -com internetexplorer.application;
$IE.Visible = $true;
$IE.Navigate($url);

# Wait a few seconds and then launch the executable.
while ($IE.Busy -eq $true) {
  Start-Sleep -Milliseconds 5000;
}

# The following UsernameElement, PasswordElement, and LoginElement need
# to be modified first.  See the notes at the top of the script for more
# details.
$IE.Document.getElementById("Email").value = $Username
$IE.Document.getElementById("signIn").Click()
$IE.Document.getElementByID("Passwd").value=$Password
$IE.Document.getElementById("signIn").Click()

while ($IE.Busy -eq $true) {
  Start-Sleep -Milliseconds 5000;
}

Invoke-Item $Executable

【问题讨论】:

  • 我觉得你的代码中的双引号很奇怪,可能是问题来自于此吗?尝试用"Email"替换“Email”
  • 我按照您的指南替换了它。Dint 工作。

标签: windows powershell powershell-5.0


【解决方案1】:

如果您的邮件地址无效,您将永远不会收到密码字段,而是一条错误消息。 对我来说它正在工作。

【讨论】:

  • 我确实交叉检查了邮件地址是否有效,并检查了其他邮件 ID 是否无效。
  • 您的 IE 窗口显示什么?如果您看到已登录的帐户,请注销。登录时,我得到了和你一样的错误。在我注销并重试后,它成功登录。但是:一般来说,在 ps1 脚本中“共享”您的 google 密码并不是一个好主意 :) 谁可以访问该文件,谁就可以获得您的邮件帐户。
  • IE 窗口打开时会提示输入电子邮件地址的登录提示。它没有登录任何其他帐户。我基本上只是在测试这是否有效,以便我以后可以继续进行:)。但不知道为什么会出现这个错误。后续行的第一个字符有问题。
  • 您的 IE 是否受到某种限制并阻止对 $IE.Document.getElementById 的访问,因为您收到了 COMException。
  • 嗨,马丁,我检查了 facebook 和其他网站,这个脚本工作正常。不确定 gmail 有什么问题。尽管如此,代码仍然有效:)。感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-01-07
  • 1970-01-01
  • 1970-01-01
  • 2014-08-12
  • 1970-01-01
  • 2021-10-25
  • 2019-05-26
相关资源
最近更新 更多