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)
I'm getting an error when I use that solution.
I was getting the 0x800A01B6 error. Now, using IHTMLDocument3_getElementByID, I get a different error: Method invocation failed because [System.__ComObject] does not contain a method named 'IHTMLDocument3_getElementByID'. At C:\Users\KenW\Desktop\PS Scripts\ISA_KW_RebootPoEDevices_v2_20161104.ps1:618 char:3 + $iframe = $global:doc.IHTMLDocument3_getElementByID($frameID) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (IHTMLDocument3_getElementByID:String) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound In which version of PS did IHTMLDocument3_getElementByID become available?
Thanks for this! I'm creating
Thanks for this! I'm creating an API scrapper and kept running into that error.
Thanks a Lot, I'm looking for
Thanks a Lot, I'm looking for a Workaround for a looooong time and this method works like a charm. Thank you so much.
Thank you
looking all over for this answer, Glad you posted!
Need help
Thanks for posting this. i was able to login to website. problem is, after logging to website i am trying to assign below value to a textarea- (xe.Document.IHTMLDocument3_getElementsById("id_1023") | select -first 1).value= "CRQ001234"; after executing above code, the text "CRQ001234" is displayed in textarea but when i click on search, it is giving error like 'no search value provided'. That means this value is not getting assigned to textarea element. how to get the value assigned to textarea element. (by the way the website i am trying is bmc remedy )
You cured my headache :-)
This problem was driving nuts. Thank you very much!!!
Seriously Saved Me
I couldn't find a solution anywhere. This needs to be posted around more so people can see it! So helpful
Add new comment
By submitting this form, you accept the Mollom privacy policy.