Sunday, November 27, 2011

1 Web UI Automation using PowerShell

Recently, I come across the need for simulate the user browser web behavior. I need to simulate the user behavior by going to particular URL, filling the form and submit the request and even download the file.

There defiantly will be more then one way can do it. I intend to focus on the solution which can use the language I familiar with: Perl and PowerShell.

Perl: LWP::UserAgent seems to be the way to go. This seems to be able to send the HTTP POST request. During my very short period time of testing. It does not work for me. Probably is because I do not have the proxy server set up. ( My environment has some proxy server/firewall restriction).

Also, since I may need to implement the solution on the windows. I spend more time on digging the solution for PowerShell.

DotNet  WebClient class seems can achieve similar way like LWP. I have not spend much time on it yet. I found the “InternetExplorer.Application” is very interesting and easy to use.

Here is some testing sample code

  1. $ie = new-object -com "InternetExplorer.Application"
  3. $ie.navigate("")
  5. While ( $ie.busy -eq $true){
  6. [System.Threading.Thread]::Sleep(2000)
  7. }
  9. $doc = $ie.document
  10. $tb1 = $doc.getElementByID("Email")
  11. $tb2 = $doc.getElementByID("Passwd")
  12. $btn = $doc.getElementByID("signIn")
  14. $tb1.value = 'XXXX'
  15. $tb2.value = 'XXXX'
  16. $
  18. $ie.visible = $true

I use the Firefox plugin firebug to find the proper HTML tag.


The current issue I am having is by using this approach to download the file. When I try to download the text file, it will be blocked by the information bar. Since in the real production environment, I do not have permission to disable the information bar via HKLM register key nor adding the website to the trust zone in IE. I have stuck on this for now.

One of limitation using this is that you have to have the Internet explorer install on the same host where you run the PowerShell. Since you are running the PowerShell already. I wont think it is much of big deal. However, I do concern about the Internet Explorer stability. I am not sure what if the IE has a lot of plugin or not stable, how would it impact the PowerShell Script.


Web UI Automation with Windows PowerShell


  1. Rolex watches Replica Oyster Perpetual Submarinerare crafted from Replica Watches UK the finest raw materials and assembled with scrupulous attention to detail. Every component is designed, developed and produced in-house to the most exacting standards.



SQL Panda Copyright © 2011 - |- Template created by O Pregador - |- Powered by Blogger Templates