Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

HTML Inspector

0.00/5 (No votes)
30 Jul 2009 1  
HTML Inspector is a really tiny utility that I wrote to spy on HTML pages
HtmlInspector.jpg

Introduction

HTML inspector is a really tiny utility that I wrote to spy on HTML pages. It is written in C# with just a couple of lines.

It uses a web browser control for displaying web pages and a property grid control to display the attributes of the selected element. We can find everything about an HTML element by just clicking on it. If you make changes in the property grid, it will be reflected on the page.

Background

I was involved with a project that automates web pages using scripts. Small scripts can be written in VBScript to do tasks like finding an element on a web page and then clicking on it. But then came a problem. How would we get the attributes of an element without going through the tones of code that make up a page?.

The solution, HTML Inspector.

Using the Code

How does it work?

First add a click event handler to the WebBrowser’s document object’s click event. Then in the event handler, find the active element on the page and assign it to the Selected element property of the property grid.

 private void Browser_DocumentCompleted
	(object sender, WebBrowserDocumentCompletedEventArgs e)
 {
        // add a handler for Click event
        Browser.Document.Click += new HtmlElementEventHandler(Document_Click);
 }

   void Document_Click(object sender, HtmlElementEventArgs e)
  {
            // Assign the selected object to property grid
            PropGrid.SelectedObject = ((HtmlDocument)sender).ActiveElement;
  }

Browse is the web browser control and PropGrid is the property grid control.

Points of Interest

The nifty technology that works behind the scenes to make things so simple is Reflection.

ALL HAIL REFLECTION !!

The icons used in this tool are from http://www.famfamfam.com/lab/icons/silk/. It is a really nice collection of icons that are free to use as you like. I wish to thank the author Mark James for this wonderful collection of icons.

History

  • 30th July, 2009 - First version released

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here