Click here to Skip to main content
Click here to Skip to main content

Automating Internet Explorer

, 24 Feb 2005
Rate this:
Please Sign up or sign in to vote.
An article describing how to automate IE, mainly for testing purposes.


I attended an ASP.NET Users Group meeting and saw a presentation given by Demetrie Gerodimos. He is an Architect at Dell and was giving a presentation on Test Driven Development. An interesting point of his presentation for me was when he explained how they execute their tests. A discussion with him after the meeting revealed that they were automating Internet Explorer to test their ASPX pages.

After spending some time researching how easily you can automate Internet Explorer in C# (with the help of some URLs given to me by Demetrie), I began writing my own version of IEDriver. The URLs I looked at had a basic example of how to instruct IE to perform various actions. Over the course of the last year, I have enhanced my IEDriver class to handle other types of interactions with IE that I have required. While this is by no means a complete automation class, I believe it performs many of the common functions needed when writing automated tests.


The basic idea here is that we will use Interop services to invoke methods on the COM interfaces built into Internet Explorer. I have written this article because the documentation available on these interfaces is scarce at best. I have spent a lot of time researching on the web and doing trial and error experimentation with these interfaces to produce much of this IEDriver class.

Using the code

The gist of it is a class called IEDriver. This class' constructor will create a new IEXPLORE.EXE process and attach to it. From then on, the methods on the IEDriver class can be used to simulate a user using his browser. While I have not implemented every type of interaction you could have with your browser, I have implemented most of the routines that I have needed to write automated tests for my product.

I have tried to hide the inner workings of the driver from the user of the class. You will notice that there are ClickXXX methods and GetXXX values that will deal with all the COM interfaces to perform the actions necessary or return the value you are interested in.

Here is an example of how easy this class is to use. This example will simply navigate to Google and search for "Automating Internet Explorer":

IEDriver driver = new IEDriver();
driver.SetInputStringValue("q", "Internet Explorer Automation");

In this example, "q" is the name of the input control and "btnG" is the name of the button control on the Google page. Preferably, you will have ID attributes on your HTML elements, but if there is no ID attribute, the driver will find the element with a name attribute.

In order to use this code, you will need to do a couple of things. First of all, you will need to add a couple of references to your project. To do this, right click on References and click Add Reference:

Right click references and select Add Reference

When the Add Reference dialog comes up, first select the .NET tab. Scroll down to the Microsoft.MSHtml object, and click the Select button.

Select the Microsoft.mshtml .Net object

Next, click on the COM tab. Scroll down to the Microsoft Internet Controls object and click the Select button.

Select the Microsoft Internet Controls COM object

Now click on OK. This will add the necessary references to your project that will allow IEDriver class to make the necessary calls to automate IE.

Once you have added the appropriate references to your project, just include the IEDriver in your project. Now, all you have to do is import the IEAutomation namespace into your class and you can begin writing automated tests using IE.

Points of Interest

One thing to keep in mind. The documentation on this stuff is not very good so if you need to enhance IEDriver to support a feature that it currently doesn't, your best bet is probably to use your intellisense to invoke a method that you think might do what you want, and assign the variable to some temporary local variable. Then, fire up your debugger and use the watch window to find out all you can about the objects returned.


While writing my own automated tests, I have discovered that it is useful to extend the IEDriver class and add methods that do tasks that I might perform quite often so that I can use the intellisense and the compiler to eliminate the possibility of mistyping control names. For example:

class MyIEDriver : IEDriver {
    public void ClickSave() {

This gives you compiler checking for things that may normally only be caught at runtime.


  • 2-23-2005: Initial release.

Other Articles

Writing Automated Tests With NUnit and IE.


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


About the Author

Leslie Hanks
Web Developer
United States United States
A developer for ScienceTRAX, LLC


Comments and Discussions

GeneralRe: Added useful functionality... hope this helps. PinmemberTriLogic16-Mar-07 6:07 
GeneralRe: Added useful functionality... hope this helps. PinmemberNinjaCross28-Jun-07 4:55 
GeneralonClick and javascript... PinmemberTriLogic28-Feb-07 11:27 
GeneralRe: onClick and javascript - SOLVED. PinmemberTriLogic28-Feb-07 12:59 
GeneralPopulating a file path PinmemberFrankSuero19-Dec-06 10:54 
AnswerRe: Populating a file path Pinmembershawn4school19-Apr-07 6:55 
GeneralError in VS 2005 Pinmembergasbh10-Oct-06 18:47 
AnswerRe: Error in VS 2005 Pinmemberjmd170112-Nov-06 9:44 
GeneralAutomation and SW Explorer Pinmemberdocrob18-Sep-06 5:02 
QuestionGetting Javascript to execute.. Pinmemberpjbm4-Sep-06 19:07 
GeneralVery useful Pinmembercgreen691-Sep-06 5:42 
NewsMany of the below things possible PinmemberPrashant Goswami30-Aug-06 1:35 
GeneralRe: Many of the below things possible PinmemberTriLogic28-Feb-07 11:22 
GeneralUseful article PinmemberPrashant Goswami28-Aug-06 3:51 
GeneralAlternative script recording based automation of web applications, etc. Pinmemberdaluu21-Aug-06 13:21 
Questionhow to fill the user/pass fields in the popUp window of the HTACCESS from c# Pinmembervedmack4-Aug-06 0:30 
AnswerRe: how to fill the user/pass fields in the popUp window of the HTACCESS from c# Pinmemberdaluu21-Aug-06 13:27 
GeneralTextArea Pinmemberwumqzj16-Jul-06 21:03 
GeneralRe: TextArea [modified] PinmemberLeslie H20-Jul-06 23:26 
GeneralRadio Buttons PinmemberHazem-mk12-Jul-06 2:01 
GeneralThank you! Pinmembernpbuggia17-Mar-06 22:15 
GeneralNeed some help with the browser Pinmembertaiseng14-Feb-06 17:45 
GeneralRe: Need some help with the browser PinmemberAlex Furman15-Feb-06 7:57 
GeneralClicking on more than one button with same name PinmemberFausto Luis17-Jan-06 5:24 
GeneralAutomation of Login Pinmemberscotch_man6-Jan-06 11:51 
GeneralRe: Automation of Login PinmemberLeslie Hanks6-Jan-06 12:07 
GeneralRe: Automation of Login Pinmemberscotch_man7-Jan-06 11:37 
GeneralRe: Automation of Login using SWExplorerAutomation PinmemberAlex Furman9-Jan-06 12:21 
GeneralPost PinmemberSilveraxx2-Jan-06 2:34 
GeneralRe: Post PinmemberLeslie Hanks6-Jan-06 12:13 
GeneralFrames Pinmembers1s116-Dec-05 15:36 
GeneralRe: Frames PinmemberAlex Furman21-Dec-05 7:03 
GeneralRe: Frames PinmemberCristi Lupascu30-Jan-07 4:04 
QuestionClicking a button with no name? PinmemberAndyChatzi14-Oct-05 6:26 
AnswerRe: Clicking a button with no name? Pinmemberscotch_man6-Jan-06 11:28 
QuestionRe: Clicking a button with no name? PinmemberCTIDude14-Oct-06 16:26 
QuestionHow to hide the IE window? Pinmemberjoohn12-Oct-05 6:45 
AnswerRe: How to hide the IE window? Pinmemberscotch_man6-Jan-06 11:48 
Generalvery nice article Pinmemberaspexpert20006-Sep-05 11:09 
QuestionHow to write new values into File Input PinmemberLF-X18-Aug-05 23:26 
AnswerRe: How to write new values into File Input Pinmemberhcanfly21-Jun-06 9:11 
GeneralRe: How to write new values into File Input PinmemberLF-X5-Jul-06 3:02 
GeneralIEDriver Constructor PinmemberTexio10-Aug-05 14:08 
QuestionHow do you get hold of a pop up window? PinmemberSteve Hurcombe26-May-05 4:22 
AnswerRe: How do you get hold of a pop up window? PinmemberSteve Hurcombe1-Jun-05 4:19 
GeneralCode Contribution: Some new methods PinmemberSteve Hurcombe26-May-05 4:18 
GeneralVery Nicely Done Pinmemberjmccaffrey26-Apr-05 12:20 
Generalpadlock icon of browser Pinmembersinale23-Apr-05 19:53 
GeneralSetting TextBox Contents PinsussCraig McF22-Apr-05 7:45 
GeneralFrames Pinmembergumigyuri6-Mar-05 20:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150414.1 | Last Updated 25 Feb 2005
Article Copyright 2005 by Leslie Hanks
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid