"未指定的错误"调用getElementById()时

时间:2016-01-25 06:59:57

标签: windows powershell powershell-v5.0

执行以下脚本时出现此错误。还提到了相同的输出。我确实检查了错误但dint找到了任何修复。我使用的是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

1 个答案:

答案 0 :(得分:0)

如果您的邮件地址无效,您将永远不会收到密码字段,但会收到错误消息。 对我而言,它正在发挥作用。