Wednesday, February 13, 2008

Catch events fired by web browser in windows application

Recently one of my collegues Hari came up with something which i really liked and thought should share.

He had a requirement in which , he had a windows application which had a WebBrowser component in it. The requirement was that he needs to catch certain events fired by the contends (button,link) of the HTML page rendered in the webbrowser component.

What i liked about solution was the simplicity. All that was required to be done was a single line of code.

webBrowser1.Document.GetElementById("btn1").Click += new HtmlElementEventHandler(ButtonHTMLClicked);

Now isn't that kool.What are the possible areas of exploration for this ?? How about building a lightweight browser component that can enable you to do automated tests for websites just like QTP ??