我正在尝试查找网页中是否存在元素:
$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
(是的, http: //10.0.0.1的页面可能不包含 id 为“admin”的元素 - 为什么不重要。)
我的问题是第 5 行中的测试似乎无法正常工作:无论元素是否存在,它总是返回 TRUE。我也试过
if ($ie.Document.getElementById("admin") -ne $NULL) {...}
结果相同。
我正在使用 Windows 10 系统。有任何想法吗?