I followed this article, explaining how to spice up an Internet Explorer COM-Object with jQuery. While the author used Python, I want to do something similar in Powershell.
Right now I have this code:
function addJQuery ($browser) {
$url="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"
$document = $browser.document
$window = $document.parentWindow
$head = @($document.getElementsByTagName("head"))[0]
$script = $document.createElement("script")
$script.type = "text/javascript"
$script.src = $url
$head.appendChild($script)
while (!$window.jQuery) {
sleep -milliseconds 100
}
return $window.jQuery
}
$ie = New-Object -comobject InternetExplorer.Application
$ie.visible = $true
$ie.Navigate("https://some.site.com")
while ($ie.busy) {start-sleep -milliseconds 500}
$j = addJQuery $ie
With Fiddler and via the document.scripts collection I verified that the file gets downloaded. However, the script sleeps forever and when I try to output $window.jQuery it prints nothing in the Powershell ISE console.
The Script is nevertheless correctly loaded, since jQuery-Functions can be called from the browser's console or via execScript().
It seems the problem is that the DOM-representation available via $ie.document isn't updated when DOM-changes are made via JavaScript. But shouldn't the Internet Explorer COM-Object behave the same way in Powershell as it does in Python?