表单提交后无法使用Powershell关闭Internet Explorer

表单提交后无法使用Powershell关闭Internet Explorer,powershell,Powershell,我打开一个页面,填写字段,单击提交。submit执行重定向。当我尝试$ie2.quit()时,它不会关闭窗口。有什么想法吗 $ie2 = New-Object -com InternetExplorer.Application $ie2.visible=$true $ie2.navigate("http://localhost/useradd.jsp") start-sleep -seconds 3 $ie2.Document.getElementById("UserId").value =

我打开一个页面,填写字段,单击提交。submit执行重定向。当我尝试$ie2.quit()时,它不会关闭窗口。有什么想法吗

$ie2 = New-Object -com InternetExplorer.Application
$ie2.visible=$true
$ie2.navigate("http://localhost/useradd.jsp")
start-sleep -seconds 3

$ie2.Document.getElementById("UserId").value = "test1"
$ie2.Document.getElementById("UserName").value = "test1 user"
$ie2.Document.getElementById("UserPassword").value = "12345$"

$submitButton = $ie2.document.getElementsByTagName("input") 
Foreach($element in $submitButton )
{
    #look for this field by value this is the field(look for screenshot below) 
    if($element.value -eq "Add"){
    Write-Host $element.click()
}
$ie2.quit()

尝试在
$ie2.quit()
语句之前添加类似
while($ie2.Busy){Start Sleep-Seconds 1}
的内容,以确保COM对象具有重复性