Tag Archives: Microsoft html library class

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 = http://www.google.com/”; //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”)