Wednesday, December 09, 2009

IE8 automation: How to programatically open an URL - Tutorial (2)

Get started with web macros in IE

Every web macro has to start somewhere, has to start somehow. There are basically two scenarios of automating Internet Explorer browser:
  • start a new IE browser and navigate to a URL to begin with

  • connect to an existing instance of Internet Explorer browser and continue automation
In this short tutorial I'll show you how to open a new Internet Explorer browser and open an URL with Twebst Automation Studio. Let's start with a short JScript web macro.
var core    = new ActiveXObject('Twebst.Core');
var browser = core.StartBrowser('');
The code is quite self-explaining. It creates a Twebst object and then opens a given URL in a new IE browser instance. What you get back from StartBrowser call is a Browser object that can be used to further automate Internet Explorer.

What can you do with a browser object? Quite a lot of things: navigate to a URL, find HTML elements and frames inside it, close the browser, get information about the browser, automate modal and modeless HTML dialgos and wait to complete navigation and loading.

That's all for now, but these feature will be covered in next tutorials!

(Automation Library and Macro Recorder for Internet Explorer)


Anish Philip said...

Hi Adrian,

I have a problem, which is unrelated to this post, on which I would like to have some advice from you. Since I'm not sure how to get in touch with you directly I'm posting my problem as a comment!

The Problem is that in IE8 - the DocumentComplete event gets triggered twice for particular URLs because of which the logic suggested by MSFT here - - does not work. I have even observed that the DocumentComplete event for iframes gets triggered after the DCE for the main document.

Unknown said...


Could you tell what is the URL causing trouble? I think that nowadays AJAX-ed web sites could trigger multiple "document complete" events.

Unknown said...

Can you help me:
I am new to it.
Unable to create activex object for 'TwebstLib.Core.

First Try:
script type="text/jscript" language="jscript"

function LoadIE() {
alert('1 started.');
var core = new ActiveXObject('TwebstLib.Core');
alert('2 Core object');

nothing happens, browser keep on procesing.

Second try:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Core = TwebstLib.core;
using ICore = TwebstLib.ICore;
using IBrowser = TwebstLib.IBrowser;
using IElement = TwebstLib.IElement;
using SHDocVw;

public partial class _Default : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
ICore core = new Core();
IBrowser browser = core.StartBrowser("");
browser.FindElement("input text", "id=gbqfq").InputText("searchtext");
works when i run from VS2010 but when i publish the code and covert it to application in IIS its not working, browser keep on processing and nothing happens.
I wanted to busy this, and working on for POC.
I would be thank full to you, if anyhow you can help me in.

Unknown said...
This comment has been removed by the author.
Unknown said...


From what I understand the first JS code runs on the client side in IE browser and the second runs on the server and it's

The first case won't work if the client does not have Twebst locally installed and it is subject to browser security restrictions (creating ActiveX objects from JScript).

The second point is still an unresolved issue. see: