BLOG
Wissenstransfer von IT-Spezialisten
| |

PowerShell Exception 0x800A01B6 while using getElementsByTagName, getElementsByName or getElementByID

To put an Azure Web-App service under heavy load I make use of the com-object „InternetExplorer.Application“ to automate an internet explorer session.

1
2
3
4
5
6
7
8
$xe = New-Object -com "InternetExplorer.Application"
$xe.visible = $true
$xe.silent = $true
$xe.Navigate($IURL)
while ($xe.Busy) {
    [System.Threading.Thread]::Sleep(10)
}

Using $xe.Document.getElementsByTagName(„Input“) enables me to enumerate the form fields and buttons. This works for the first website that I am visiting. If I then navigate to another site, $xe.Document.getElementsByTagName(„Input“) generates the following exception:

1
2
3
4
5
6
Exception from HRESULT: 0x800A01B6
At line:1 char:1
+ $Global:ie.Document.getElementsByTagName("Input")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], NotSupportedException
    + FullyQualifiedErrorId : System.NotSupportedException

Workaround:

Always use the following methods instead of the native ones:

1
2
3
IHTMLDocument3_getElementsByTagName
IHTMLDocument3_getElementsByName
IHTMLDocument3_getElementByID

Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$xe = New-Object -com "InternetExplorer.Application"
$xe.visible = $true
$xe.silent = $true
 
$xe.Navigate($IURL)
while ($xe.Busy) {
    [System.Threading.Thread]::Sleep(10)
}
$xe.Document.IHTMLDocument3_getElementsByTagName("Input")
$xe.Navigate($IURL2)
while ($xe.Busy) {
    [System.Threading.Thread]::Sleep(10)
}
$xe.Document.IHTMLDocument3_getElementsByTagName("Input")