Powershell: Fire HTML Form Element Javascript with jQuery

$ie.document.Script.execScript("`$(`"#mytext`").trigger(`"change`");")

If you’re tasked with the automation of a form element, you will find that most of the time this manipulation will not fire javascript code necessary to complete your task. Consider a dynamic dropdown box – you make your selection in the first element, and now that you’ve chosen, the second element is populated. With automation you’ll be stuck trying to figure out how to get that second element populated. The code above (swap out your id element for mytext) will force the associated javascript to fire. It’s embarrassing, but this took forever for me to figure out. I had resorted to emulated keystrokes – but emulated keystrokes don’t allow your automation to continue behind a screensaver.

While I’m on it – why does the below code work? I can’t find documentation on it.

$ie.document.Script."alert".Invoke("Hi")

Leave a Reply

Your email address will not be published. Required fields are marked *