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

时间:2016-03-10 16:12:15

标签: powershell

我打开一个页面,填写字段,点击提交。提交确实进行了重定向。当我尝试$ 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()

1 个答案:

答案 0 :(得分:0)

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