我正在通过Powershell访问InternetExplorer.Application
COM。我试图使用document
的querySelector
,但它不返回任何结果。我目前正在使用IE8。querySelector所有的IE COM在IE 8中都不起作用
$ie = New-Object -com "InternetExplorer.Application"
$ie.visible = $true
$ie.Navigate("www.google.com")
if ($ie.Busy) { Start-Sleep 1 }
# This statement works
@($ie.Document.getElementsByTagName("a"))[0]
# This statement doesn't work, though querySelectorAll
# exist in the document object
@($ie.Document.querySelectorAll("a"))[0]
# I tried this
$ie.Document.querySelectorAll("a") -eq $null # evaluates to True
你会得到什么错误信息?它返回什么? – ManseUK
'querySelectorAll'不返回任何东西。它返回null。 – OnesimusUnbound
在我的机器上尝试了您的代码,并得到:“方法调用失败,因为[mshtml.HTMLDocumentClass]不包含名为'querySelectorAll'的方法。” –