I am trying to find whether an element exists in a web page:
$ie = New-Object -com InternetExplorer.Application
$ie.visible = $true
$ie.Navigate("http://10.0.0.1")
BrowserReady($ie) # wait for page to finish loading
if ($ie.Document.getElementById("admin")) {
$ie.Document.getElementById("admin").value = "adminuser"
}
etc, etc
(Yes, it is possible for the page at http://10.0.0.1 to NOT contain the element with id "admin" - the why doesn't matter.)
My problem is that the test in line 5 doesn't seem to work correctly: it always returns TRUE whether the element exists or not. I have also tried
if ($ie.Document.getElementById("admin") -ne $NULL) {...}
with same results.
I am working on a Windows 10 system. Any ideas?