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!
Workaround Always use the following methods instead of the native ones:
IHTMLDocument3_getElementsByTagName
IHTMLDocument3_getElementsByName
IHTMLDocument3_getElementByID
Thanks to Paul Lim Here
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With