PowerShell Exception 0x800A01B6 while using getElementsByTagName, getElementsByName or getElementByID

Marcel Meurer's picture

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. 

$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:

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:

IHTMLDocument3_getElementsByTagName 
IHTMLDocument3_getElementsByName 
IHTMLDocument3_getElementByID

Example:

$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") 

Comments
Thank You!
Thanks, this was driving me nuts!
Thanks so much! I was also
Thanks so much! I was also going crazy trying to figure this out.
Huge Help
Thank you for posting this!
looking for this you are a saver
wow ! thx , usually I am writing in perl and bash , trying the blue screen jjjj
Nice!
thanks!
THANKS!
Thank you so much lol, this should be first on google (but its like 4th)
Add new comment
By submitting this form, you accept the Mollom privacy policy.