S
S
Sergey2016-03-09 17:51:55
PowerShell
Sergey, 2016-03-09 17:51:55

Why is the error "Exception from HRESULT: 0x80020101" thrown when calling getElementById()?

I am writing a script in Powershell.
1. When trying to get an element into a variable, an exception is thrown.

$ie = New-Object -ComObject "InternetExplorer.application"
$ie.visible = 1
while ($ie.Busy -eq $true) { Start-Sleep 1 }
$ie.Navigate("http://vk.com")
$ie.Document.getElementById('quick_email').value = 'mail'
$ie.Document.getElementById('quick_pass').value = 'pass'
$ie.Document.getElementById("quick_login_button").click();

1af172038f88420fb8faaffd93989ed4.png
If for getting the form I found a workaround
$ie.Document.forms[0].elements[8].value = 'email'
$ie.Document.forms[0].elements[9].value = 'pass'

, then for the button and the event I can not find it.
2. How to get a collection of DOM elements? Not only forms, but other types?
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
azarij, 2016-03-10
@azarij

Your code works OK for me like this:

$ie = New-Object -ComObject "InternetExplorer.application"
$ie.visible = 1
$ie.Navigate("http://vk.com")
while ($ie.Busy -eq $true) { Start-Sleep 1 }
$ie.Document.getElementById('quick_email').value = 'mail'
$ie.Document.getElementById('quick_pass').value = 'pass'
$ie.Document.getElementById("quick_login_button").click();

swapped lines 3 and 4.
win10, ps5, ie11

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question