Internet explorer automation

Automating internet explorer from dotnet is possible through c# given below is a sample

To use the below code add reference to Microsoft.mshtml class and Microsoft html library class

To assist you in finding the names of html controls and their id’s use internet developer toolbar available from Microsoft (click here to get it now)    

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using SHDocVw; using System.IO;

using System.Security.Cryptography;

namespace ie


public partial class Form1 : Form

public Form1()




private void button1_Click(object sender, EventArgs e)


Object nullob = null;

Object URL =”; //Use the url of webpage to automate

mshtml.HTMLDocumentClass doc;   

InternetExplorer ie = new

ie.Visible = true;

ie.Navigate2(ref URL, ref nullob, ref nullob, ref nullob, ref nullob);







doc = (mshtml.HTMLDocumentClass)ie.Document;

mshtml.HTMLInputElementClass inputel = (mshtml.HTMLInputElementClass)doc.all.item(“sometextboxid”, null);

inputel.value = “sometext”; //Text needed to be filled in textbox get the text box id from source


inputel = (mshtml.HTMLInputElementClass)doc.all.item(“sometextboxid”, null);

inputel.value = “sometext”;


mshtml.HTMLSelectElementClass inputsel = (mshtml.HTMLSelectElementClass)doc.all.item(“questions”, null);

inputsel.selectedIndex = 2; //dropdown select


foreach (mshtml.HTMLInputElementClass inp in doc.getElementsByTagName(“INPUT”))

{ // to click the button in webpage

if (inp.value == “submit”)







4 responses to “Internet explorer automation

  1. Very interesting article indeed.
    What is the integrity level of the launched IE browser on Windows Vista? I believe it runs at medium integrity level and that means that protected mode is off.

  2. The security level is medium or medium high.As it doesnt involves any activex controls the security level doesnt changes.Moreover it works fine with windows XP and IE7.Integrity with windows vista is under testing

  3. Hi Mani,

    This is a great inspiration to Automate Internet Explorer.

    I would like to discuss the next possibility of being able to automate opening different Internet Explorer Windows and automating the browsing on different tabs. I have managed to Navigate the different URLs in different tabs however am not able to get a reference to the Website in another tab.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s