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
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
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();
User contributions licensed under CC BY-SA 3.0