I have an array, $Conventional, which I need to loop through and click each time so that I can save the PDFs which are made available after the click().
$Conventional = @()
$Conventional = $ie.Document.getElementsByTagName("td") | ? {($_.getAttributeNode('class').Value -match 'NodeDocument') -and ($_.innerText -notmatch 'Library Home')}
This fills $Conventional with four td elements which I need to loop through and click() each time. The following is my ForEach loop which works fine on the first iteration, however it then fails and returns System.ComObject each time after that.
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
}
Here is a screenshot of the array I am capturing. In order to retrieve the PDFs, each one needs to be clicked.

Any help would really be appreciated. Thanks everyone
foreach(){}sometimes have problems with the collections returned by COM applications because they don't properly implementIEnumerable. Try with$Conventional |ForEach-Object { $_.InnerText }instead@()to instantiate a powershell array variable, use a .Net array with= New-Object System.Collections.ArrayListthen attempt to add to your array. I wouldn't trust powershell to automatically box the output from$ie..getElementsById()so I'd work in powershell to make sure your elements are being returned first, then if they are being casted to your array properly second, and then work with each element in a foreach loop after confirming the elements are being formatted correctly.