Internet Explorer Automation with WatIN

At my workplace I use an IT Service Desk application, called well, "Service Desk" from CA. The system is web-based and provides various queues for Change Orders, Requests and Incidents. Service Desk is used as used as workflow system instead of email. I'm sure this is a pretty common practice for many large IT shops, although they may use a different application. The Service Desk application is one the applications I like to keep open all day, however there is a 60 minute inactivity timeout. By doing any activity within a 60 minute timeframe you avoid timing out, even something simple like clicking an update count button.

So, I thought I would create a PowerShell that would click an update count button every 50 mintues. I've done some scripting using Internet Explorer COM automation and PowerShell. This involves creating an InternetExplorer.Application object and reading through the page source to find the HTML elements I want to select. I soon discovered issues pragmatically getting to the button through this technique due to Service Desk's heavy used of nested frames within nested frames. I decided to go another route using WaitIN, WaitIN Recorder and PowerShell.

Joel Bennet has a post on Using PowerShell and WatiN, which I found helpful. Although I did not use the functions he created, his post provides a quick introduction to PowerShell and WaitIN. Running WaitIN requires starting PowerShell in STA mode, so this is a PowerShell V2 only script. To start PowerShell in STA mode run:

powershell.exe -STA

Getting Started

Usually working with PowerShell you'll create an object and explore it's property and methods, however in this case trying to find the button name was a little difficult. This is where WatIN Recorder helps out. After you've installed WatIN Recorder, run as a Administrator and navigate to the URL you want to automate:

Next click the record button and click the HTML element you want to automate. Then stop the WatIN recorder and click copy code to clipboard icon. This will produce some C# code that just needs to be translated into PowerShell: