使用internetexplorer对象等待ajax响应的正确方法是什么?

使用internetexplorer对象等待ajax响应的正确方法是什么?,ajax,internet-explorer,powershell,sharepoint,webautomation,Ajax,Internet Explorer,Powershell,Sharepoint,Webautomation,我试图将文件上传到sharepoint库,但我的代码无法正确检测ie是否仍在等待ajax响应。正确的方法是什么 [void] [System.Reflection.Assembly]::LoadWithPartialName("'Microsoft.VisualBasic") [void] [System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms") function wait4IE($ie=$global

我试图将文件上传到sharepoint库,但我的代码无法正确检测ie是否仍在等待ajax响应。正确的方法是什么

[void] [System.Reflection.Assembly]::LoadWithPartialName("'Microsoft.VisualBasic")
[void] [System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms")

function wait4IE($ie=$global:ie){
    while ($ie.busy -or $ie.readystate -lt 4){start-sleep -milliseconds 200}
}

$global:ie=new-object -com "internetexplorer.application"
$ie.visible=$true
[Microsoft.VisualBasic.Interaction]::AppActivate("internet explorer")

# open EDM
$ie.navigate("https://xxx.sharepoint.com/sites/site1/Forms/AllItems.aspx")
wait4IE

# click on  the button to display the form
$ie.Document.getElementById("QCB1_Button2").click()

wait4IE
代码的其余部分已执行,但尚未显示上载表单。 如何等待表单的显示

我也尝试过这个(应该等到上传表单的按钮找不到为止),但它永远不会结束

while( $ie.document.getElementById("ctl00_PlaceHolderMain_UploadDocumentSection_ctl05_InputFile") -eq $null){
        echo "waiting ..."
        wait4IE
}

更新: 我想我已经发现了问题:表单是在iframe中打开的:

<iframe id="DlgFrame0be35d71-22cb-47bd-bbf0-44c97db61fd6" class="ms-dlgFrame" src="https://.../Upload.aspx?List={45085FA0-3AE3-4410-88AD-3E80A218FC0C}&amp;RootFolder=&amp;IsDlg=1" frameborder="0" style="width: 592px; height: 335px;"></iframe>
此外,似乎我可以使用getElementsByTagName访问框架内容,但不能使用getElementById…?我仍然不明白为什么:

PS>$ie.Document.frames.Item(4).document.body.getElementById('ctl00_PlaceHolderMain_UploadDocumentSection_ctl05_InputFile
    ')
    Échec lors de l'appel de la méthode, car [System.__ComObject] ne contient pas de méthode nommée « getElementById ».
    Au caractère Ligne:1 : 1
    + $ie.Document.frames.Item(4).document.body.getElementById('ctl00_PlaceHolderMain_ ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation : (getElementById:String) [], RuntimeException
        + FullyQualifiedErrorId : MethodNotFound
好的,我是这样做的: 诀窍是查看每个iFrame,选择一个具有正确位置的iFrame

for($i=0;$i -lt $ie.Document.frames.length;$i++){
            if( $ie.Document.frames.item($i).location.href -match 'upload.aspx' ){ $frm=$ie.Document.frames.item($i)}
    }
然后等待我的输入显示

while( ($frm.document.body.getElementsbytagname("input") |?{$_.type -eq 'file'}) -eq $null){
    echo "waiting ..."
    start-sleep -milliseconds 100
}
while( ($frm.document.body.getElementsbytagname("input") |?{$_.type -eq 'file'}) -eq $null){
    echo "waiting ..."
    start-sleep -milliseconds 100
}