3

I'm accessing the InternetExplorer.Application COM through Powershell. I'm trying to use the querySelector of the document, but it doesn't return any result. I'm currently using IE8.

$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
OnesimusUnbound
  • 2,886
  • 3
  • 30
  • 40

1 Answers1

0

Use the IDocumentSelector prefix to reference the method, using something like this:

$ie.Document.IDocumentSelector_querySelectorAll("a")

There are one or two powershell browser API troubleshooting resources which may help. Sizzle may help if the doctype is causing the browser to render is almost standards or quirks modes, which do not support querySelectorAll.

Community
  • 1
  • 1
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
  • `$ie.Document.IDocumentSelector_querySelectorAll("a")` didn't worked. Anyway, I haven't explored the links you've post. I'll try to look on them on weekend. – OnesimusUnbound Sep 26 '12 at 06:29
  • I need a css selector function to search beyond simple id or name element name. Hmmm, Sizzle may do the trick. Anyway, I'll try it within this week. – OnesimusUnbound Oct 01 '12 at 13:33