0
我试图找到在网页中是否存在一个元素:PowerShell的:测试在网页是否存在一个元素
$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系统。有任何想法吗?
因此,在'if'语句中测试 –
D'oh!我正在阅读它,但认为它正在测试'不存在' – TessellatingHeckler