'Exception from HRESULT: 0X800A01B6' error in PowerShell when trying to enter login information to Facebook

5

I have this code written in PowerShell:

$username = "xxxxxx";
$password = "xxxxxx";
$url = "www.facebook.com/login";

$ie = New-Object -com internetexplorer.application;
$ie.visible = $true;
$ie.navigate($url);

($ie.document.getElementsByName("email") |select -first 1).value = $username;

And there is when I get this error message:

Exception from HRESULT: 0x800A01B6
At line:1 char:1
+ ($ie.document.getElementsByName("email") |select -first 1).value = $u ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : OperationStopped: (:) [], NotSupportedException
+ FullyQualifiedErrorId : System.NotSupportedException

Any solutions?

Thank you!

powershell
asked on Stack Overflow Jun 14, 2016 by jfhgkjhgk • edited Jun 15, 2016 by halfer

4 Answers

9

Workaround Always use the following methods instead of the native ones:

IHTMLDocument3_getElementsByTagName   
IHTMLDocument3_getElementsByName
IHTMLDocument3_getElementByID

Thanks to Paul Lim Here

answered on Stack Overflow Sep 2, 2018 by Wendolin Salazar Flete • edited Jan 9, 2019 by Maximilian Burszley
2

This might happen as IE is still loading the page or parsing DOM. Try waiting for IE not to be busy before accessing page elements. A simple check for IE's Busy property will do. Like so,

$username="myname"
$password="mypass"
$url = "www.facebook.com/login"
$ie = New-Object -com internetexplorer.application
$ie.visible = $true
$ie.navigate($url)

# Sleep while IE is busy. Check 10 times per second, adjust delay as needed
while($ie.Busy) { Start-Sleep -Milliseconds 100 }

# IE is not busy with document anymore, pass credentials and click the logon    
($ie.document.getElementsByName("email") |select -first 1).value = $username
($ie.document.getElementsByName("pass") |select -first 1).value = $password
($ie.document.getElementsByName("login") |select -first 1).click()
answered on Stack Overflow Jun 15, 2016 by vonPryz
2

use this:

$Url = "http://websiteurl"
$ie = New-Object -com internetexplorer.application;
$ie.visible = $true; # make to $true to see the result in webpage
$ie.navigate($Url);
while ($ie.Busy -eq $true) { Start-Sleep -Seconds 10; }
($ie.Document.IHTMLDocument3_getElementsByName("btnname") | select -first 1).click();
$ie.quit()

answered on Stack Overflow Sep 23, 2019 by passionatedevops
0

In my experience, using

do{Start-Sleep -Milliseconds 100}While($ie.Busy -eq $True)
do{Start-Sleep -Milliseconds 100}While($ie.ReadyState -ne 4)

Still have chance get Exception from HRESULT: 0x800A01B6 error !

But if you add the code

do{
    Start-Sleep -Milliseconds 100
}While((($ie.document.getElementsByName("login")).GetType()) -eq "DBNull")

before you using $ie.document.getElementsByName then the error code 0x800A01B6 will no longer happen

answered on Stack Overflow Mar 5, 2021 by Tom Liu

User contributions licensed under CC BY-SA 3.0