"Unspecified Error" 调用 getElementById() 时

"Unspecified Error" when calling getElementById()

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

输出:

PS C:\WINDOWS\system32> C:\Users\admin\Desktop\Test.ps1
Unspecified error.
At C:\Users\admin\Desktop\Test.ps1:35 char:1
+ $IE.Document.getElementById(“Email”).value = $Username
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

Unspecified error.
At C:\Users\admin\Desktop\Test.ps1:36 char:1
+ $IE.Document.getElementById(“signIn”).Click()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

Unspecified error.
At C:\Users\admin\Desktop\Test.ps1:37 char:1
+ $IE.Document.getElementByID(“Passwd”).value=$Password
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

Unspecified error.
At 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

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