Powershell: Fire HTML Form Element Javascript with jQuery


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.



Using Python to make an API call to

import json,urllib.request
response = urllib.request.urlopen("").read()
obj = json.loads(response.decode('utf-8'))
print (obj[0]['fac_name'])

Here is how to get a response from CMS on a specific CLIA record. Here is the actual table you’re querying. CMS is actually pretty awesome to give access to all of this.


_IELinkClickByText in Powershell v2

function ClickLinkByText ([string]$arg1){
$ie.document.Script.execScript("(`$('*:contains(`"" + $arg1 + "`"):last')).click();");
while($ie.Busy) { Start-Sleep -Milliseconds 100 }

If you’re using Powershell v2 to automate IE, and the webpage you’re automating has jQuery, try this out.  I’ve been jealous of this function in Autoit, and this is much faster than the “normal” methods to find the link. If you’re on a weak workstation, much more reliable too (the IE DOM randomly fails for me).


PowerShell Exception 0x800A01B6

I wanted to draw attention to this link to save somebody that headaches that I had trying to use $ie.Document.getElementById. Hope it helps.

Exception from HRESULT: 0x800A01B6
At line:21 char:1
+ $ie.Document.getElementById("RandomButton").click;while($ie.Busy) { St ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], NotSupportedException
+ FullyQualifiedErrorId : System.NotSupportedException

Always use the following methods instead of the native ones:

  1. IHTMLDocument3_getElementsByTagName
  2. IHTMLDocument3_getElementsByName
  3. IHTMLDocument3_getElementByID