Trying to use getElementById in Powershell with IE 11, error Exception from HRESULT: 0x800A01B6

4

I'm trying to automate logging in on a website, but I can't seem to use getElementById. getElementsByClassName("whatever")[0] seems to work, but the elements I need don't have class names and I can't change that.

I'm using PS 5, IE 11. Here's an example of my code, and the resulting exception.

$url = "https://google.com"
$ie = New-Object -com "InternetExplorer.Application"
$ie.visible = $true
$ie.navigate($url)
while ($ie.Busy){Start-Sleep -Milliseconds 1000}
$ie.document.getElementById("lst-ib").value = "test"

Error:

Exception from HRESULT: 0x800A01B6
At C:\gtest.ps1:6 char:1
+ $ie.document.getElementById("lst-ib").value = "test"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], NotSupportedException
    + FullyQualifiedErrorId : System.NotSupportedException
powershell
internet-explorer-11
powershell-5.0
asked on Stack Overflow Dec 14, 2015 by Ian

2 Answers

2

logging into google

$r = Invoke-WebRequest "https://google.bg" -SessionVariable g

$r = Invoke-WebRequest 'https://accounts.google.bg/' -WebSession $g

$r.Forms['gaia_loginform'].Fields.Email = 'someuser@gmail.com'
$r.Forms['gaia_loginform'].Fields.Passwd = 'somepass'

$r = Invoke-RestMethod $r.Forms['gaia_loginform'].Action -Body $r.Forms['gaia_loginform'] -Method $r.Forms['gaia_loginform'].Method  -WebSession $g

$r = Invoke-WebRequest https://google.bg -WebSession $g

$r.Content > tmp2.html

hope that helps

answered on Stack Overflow Dec 14, 2015 by Jaqueline Vanek • edited Dec 14, 2015 by Jaqueline Vanek
1

Try using

$ie.Document.documentElement.getElementByClassName();
$ie.Document.documentElement.getElementByTagName();
$ie.Document.documentElement.getAttribute();

and for id name tagname use this

$ie.Document.IHTML3_getElementById();
$ie.Document.IHTML3_getElementByName();
$ie.Document.IHTML3_getElementByTagName();
answered on Stack Overflow Aug 10, 2018 by Ashish Kamble

User contributions licensed under CC BY-SA 3.0