Running javascript through Internet Explorer com interface using PowerShell

I am writing several Internet Explorer automation scripts using PowerShell. This is how I run the IE com object:

$ie = New-Object -com "InternetExplorer.Application"
$ie.Navigate("about:blank")
$ie.visible = $true

$doc = $ie.Document

So, I would like to do to execute some javascript in the $ doc object. For example, I have an element on the page with the onclick event that executes "submitCommand ('lookup')", so I would like to run this directly in $ doc instead of finding the object on the page and then calling the Click () method.

It would be simpler because the object does not have a name or identifier, therefore it is very important to change it, since I can only rely on its position on the page (for example, the 11th span element on the page).

Alternatively, how would you choose elements based on their class? This will help a lot since the "button" has its own class.

thanks

+5
source share
1 answer

$ covers = @ ($ ie.document.getElementsByTagName ("SPAN"))

Run the pipe to where-object command to filter out the one you need (based on its attributes), and then call the click method, for example:

$span11 = $spans | where {$_.innerText -eq 'something'}
$span11.click()
+4
source

All Articles