我有一个数组,$常规,我需要循环并点击每次,这样我可以保存在click()后可用的PDF。ForEach循环在PowerShell失败后第一次迭代
$Conventional = @()
$Conventional = $ie.Document.getElementsByTagName("td") | ? {($_.getAttributeNode('class').Value -match 'NodeDocument') -and ($_.innerText -notmatch 'Library Home')}
这充满$常规与我需要遍历并点击()每次4个td
元素。以下是我的ForEach循环,它在第一次迭代中工作正常,但它然后失败,并且每次都返回System.ComObject
。
ForEach ($i in $Conventional){
$text = $i.innerText
$i.click()
while ($ie.Busy -eq $true){Start-Sleep -Seconds 2}
$PDF = $ie.Document.getElementById("OurLibrary_LibTocUC_LandingPanel_libdocview1_DocViewDocMD1_hlViewDocument")
$currentURL = $PDF.href
$fileName = $baseFileName + "_" + $cleanText
Invoke-WebRequest -Uri $currentURL -OutFile $NewPath\$fileName.pdf -WebSession $freedom
}
这是我捕获的数组的屏幕截图。为了检索PDF,每一个都需要点击。
任何帮助真的不胜感激。谢谢大家
'foreach(){}'有时候COM应用程序返回的集合有问题,因为它们没有正确实现'IEnumerable'。用'$ Conventional | ForEach-Object {$ _。InnerText}'来代替 –
感谢您的回应,现在就试试这个! – Quanda
嗯,同样的问题按照你的建议。在第一次迭代之后,Array是空的,没有任何工作。当我删除$ _click()它会工作并打印innerText,但我需要它与$ _click()一起工作。 Grrrr ... – Quanda