【问题标题】:Using internetexplorer object what is the correct way to wait for an ajax response?使用 internetexplorer 对象等待 ajax 响应的正确方法是什么?
【发布时间】:2015-05-26 09:11:06
【问题描述】:

我尝试将文件上传到共享点库,但我的代码无法正确检测 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>

但是现在,如何获得好的帧数?

PS>($ie.Document.frames.Item(4).document.body.getElementsbytagname("input") |?{$_.type -eq 'file'}).id
ctl00_PlaceHolderMain_UploadDocumentSection_ctl05_InputFile

此外,我似乎可以使用 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

【问题讨论】:

    标签: ajax internet-explorer powershell sharepoint webautomation


    【解决方案1】:

    好的,这就是我的做法: 诀窍是查看每个 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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-08
      • 2011-03-04
      • 2013-01-09
      • 1970-01-01
      • 2015-02-05
      • 2017-09-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多