IE6 - IE11 Automation - C#, VB.Net, VBScript, JScript web macro

Introduction

Overview

What is Twebst?
Twebst Automation Studio is an advanced web automation framework for Internet Explorer that can be used within any environment that supports COM, from scripting languages (JScript, VBScript) to high level programming languages (C#, VB.Net, C++).

The framework includes two components: Twebst Web Recorder that automatically generates most of the automation code and Twebst Library which is a collection of programmable objects that creates a web automation API.

What Twebst can do?
  • automate regression tests of web applications
  • automate web actions and data-entry
  • automatically log in to different web sites
  • fill out web-forms automatically
  • extract data from web pages
  • speed up MSHTML programming
  • integrate web application with other script enabled applications

Twebst features
  • Start new browsers and navigate to a specified URL.
  • Connect to existing browsers.
  • Get full programmatic control over HTML elements and frames.
  • Intuitive names for HTML elements using the text that appears on the screen.
  • Advanced search of browsers and HTML elements using regular expressions.
  • Perform actions on all HTML controls (button, combo-box, list-box, edit-box, upload control).
  • Simulates user behaviour generating hardware or browser events.
  • Get access to native interfaces exposed by Internet Explorer so you don't need to learn new things if you already know IE web programming.
  • Synchronize web actions and navigation by waiting the page to complete in a specified timeout.
  • Available from any programming or script language that supports COM
  • Optimized search methods and collections.

Twebst Web Recorder features
  • Easily create web macros through an intuitive graphical interface.
  • Generate web automation code using the language of your choice: JScript, VBScript, C#, VB.Net, C++
  • Record web actions on all HTML controls (button, combo-box, list-box, edit-box)

System requirements

Windows XP, Windows Vista, Windows 8
Internet Explorer 6 to 11 - protected mode ready

Getting support

To get information you may use this help system and the samples that come with the installation kit. All the code samples in this help are written in JScript language. You may find the latest news and updates at www.codecentrix.com.

Do you have questions about Twebst? Need assistance? Need a custom solution for your problems? Answers come from our e-mail support at: support@codecentrix.com
© 2014 CodeCentrix Software. All rights reserved.


Twebst Automation Studio - IE9 macro recorder and web automation library

Search condition

Definition:

A search condition is a string parameter for a method that searches for Browsers, Frames or Elements It has the following format:
 "attribute  = test value" or
 "attribute != test value"

The attribute in a search condition depends on the context where the search condition appears. A search condition is true if the tested relationship between the value of the attribute and the test value is true. The valid operators in a search condition are: "=" equality and "!=" inequality.

Search conditions are used in one of the following methods: FindBrowser, FindAllBrowsers, FindElement, FindChildElement, FindAllElements,FindChildrenElements FindFrame, FindChildFrame, FindAllFrames, FindChildrenFrames, WaitToLoad.

Remarks:

If the useRegExp property is set to true, then the values in search conditions represents regular expressions.
Usually, search methods are affected by loadTimeout and searchTimeout properties.

A special zero-based index attribute is available in search condition for FindElement, FindChildElement, FindFrame and FindChildFrame methods. It specifies the ordinal position in the collection of objects generated by the remaining search conditions.

Example:

var coreObj = new ActiveXObject("Twebst.Core");
var browser = coreObj.FindBrowser("URL=http://www.codecentrix.com/");
var element = browser.FindElement("A", "href=http://www.codecentrix.com/download.htm");

See also:

Core | Browser | Frame | Element


Twebst Automation Studio - Tutorials on IE6 - IE9 automation with Excel VBA, C#, VB.Net, C++, JScript, VBScript

Tutorials

  • How to programatically open an URL
  • How to get programmatic control over HTML elements
  • How to automate existing instances of Internet Explorer
  • Automate HTML File Upload Control
  • Excel and IE automation - the WSH way
  • Extract web data into Excel.Application with browser macro
  • IE8 Automation using Excel VBA Macro
  • Web Data Extraction with C++ Web Macro
  • IE Web Login Automation
  • What's wrong with Internet Explorer Automation?
  • Move data from Excel to IE and back with VBA web macros
  • IE8 close tab programmatically


Web Automation Library for IE6, IE7, IE8, IE9 - IE macros in C#, VBA, VBScript and VB.Net

Core - IE macro object

The core object is the root of the Twebst Web Automation Library and every IE macro must create a core object in order to gain access to the other features of the web automation library. The methods it provides create Browser, Frame and Element web automation objects connected to Internet Explorer HTML web controls. The properties of the core object allow to finely tune the behavior of the other objects and methods.

 var coreObj = new ActiveXObject("Twebst.Core");
Methods
AttachToNativeBrowser | Creates a library Browser IE macro object from a native Internet Explorer browser object.
AttachToNativeElement | Creates a library Element IE macro object from a native Internet Explorer element object.
AttachToNativeFrame | Creates a library Frame IE macro object from a native Internet Explorer window object.
AttachToWnd | Creates a library Browser IE macro object from a Win32 API window handle.
FindAllBrowsers | Searches for multiple instances of Internet Explorer browser that verify a list of Search Conditions.
FindBrowser | Searches for an existing instance of Internet Explorer browser that verifies a list of Search Conditions.
GetClipboardText | The method retrieves text data from the clipboard.
NativeWindowToNativeBrowser | Retrieves a native Internet Explorer browser object ( IWebBrowser2 ) from a native window object ( IHTMLWindow2 ).
NativeWindowToNativeDocument | Retrieves a native Internet Explorer document object ( IHTMLDocument2 ) from a native window object ( IHTMLWindow2 ).
Reset | Resets all properties of core IE macro object to their default values.
SetClipboardText | The method places text on the clipboard in both ANSI and Unicode format.
StartBrowser | Starts a new instance of Internet Explorer browser and returns a Browser web macro object connected to it.
StartHiddenBrowser | Starts a new invisible instance of Internet Explorer browser and returns a Browser web macro object connected to it.
WndToNativeDocument | Retrieves a native HTML document object ( IHTMLDocument2 ) from a Internet Explorer_Server window.
Properties
asyncHtmlEvents | Determines whether HTML events will be fired up synchronously or asynchronously.
closeBrowserPopups | Automatically close IE browser popups (security alerts, auto complete, errors).
foregroundBrowser | Returns a library Browser web automation object attached to foreground Internet Explorer instance.
IEVersion | Returns the version of Internet Explorer.
isRegistered | Determines whether Twebst product is currently is registered.
lastError | Returns the error code for the last library operation.
loadTimeout | Sets or retrieves the amount of time library methods wait the web page to load.
loadTimeoutIsError | Enables or disables script exception raising when the loadTimeout has expired.
productName | Returns the name of the installed Twebst Library.
productVersion | Returns the version of the installed Twebst Library.
searchTimeout | Sets or retrieves the amount of time web automation library methods try to find HTML objects in web pages.
useHardwareInputEvents | Sets or retrieves the type of input events used to perform actions on HTML web controls.
useRegExp | Enables or disables the use of regular expressions in Search conditions.
Constants
OK_ERROR | No error occured
FAIL_ERROR | Undetermined error occurred.
INVALID_ARG_ERROR | Invald parameter in method call.
LOAD_TIMEOUT_ERROR | Load timeout expired while waiting for the web page to complete.
INDEX_OUT_OF_BOUND_ERROR | Attempt to access an element of a collection with an index that exceeds the size of the collection.
BROWSER_CONNECTION_LOST_ERROR | A web automation object was disconnected from its Internet Explorer instance.
INVALID_OPERATION_ERROR | Operation not applicable to current web automation object.
NOT_FOUND_ERROR | Item(s) not found.
See also:


IE6, IE7, IE8, IE9 macro - automate IWebBrowser2 in C#, VBA/Excel, VBScript

Browser - IE macro object

This IE macro object represents an Internet Explorer instance.
It provides web macro methods for searching Element and Frame web automation objects inside the web page DOM hierarchy, and for automating various browser actions (navigate, close, show/hide browser window).

  var browserObj = coreObj.FindBrowser(Search conditions);
  var browserObj = coreObj.FindAllBrowsers(Search conditions)(index);
  var browserObj = coreObj.AttachToNativeBrowser(native browser);
  var browserObj = frameObj.parentBrowser;
  var browserObj = elementObj.parentBrowser;
Methods
Close | Closes the Internet Explorer instance represented by the browser object.
ClosePopup | Closes a window.alert or a window.confirm popup window in Internet Explorer.
ClosePrompt | Closes a window.prompt popup window in Internet Explorer.
FindAllElements | Searches in the current browser, the collection of all HTML elements that verify a list of search conditions.
FindAllFrames | Searches in the current browser, the collection of all HTML frame and iframe objects that verify a list of search conditions.
FindElement | Searches in the current browser, an HTML element that verifies a list of search conditions.
FindFrame | Searches in the current browser, a HTML frame or iframe that verifies a list of search conditions.
FindModalHtmlDialog | Searches a Frame object in the current browser corresponding to a HTML modal dialog box.
FindModelessHtmlDialog | Searches a Frame object corresponding to a modeless HTML dialog box that verifies a list of search conditions.
Navigate | Navigates the browser to a given URL.
OpenNewTab | Opens a new Internet Explorer tab window and returns a Browser web macro object connected to it.
ShowBrowserWindow | Shows, hides, maximizes, minimizes, restores or puts in foreground the browser window.
WaitToLoad | Waits the browser to load and check it against a list of search conditions.
Properties
activeTab | Retrieves a Browser object corresponding to the active tab inside a top level IE frame.
core | Returns a reference to the parent Core IE macro object of the browser.
ieWindow | Returns the handle for Inernet Explorer_Server window of the Internet Explorer instance represented by the current Browser web macro object.
isLoading | Returns a boolean value indicating whether the browser is engaged in a navigation operation.
isTabActive | Returns a boolean value indicating whether the current tab is active or not.
nativeBrowser | Returns a native Internet Explorer browser object ( IWebBrowser2 ).
navigationError | Returns the browser navigation error code.
processId | Returns the process ID of the Internet Explorer instance represented by the Browser object.
tabList | Returns a BrowserList web automation object corresponding to all tabs windows inside the same IEFrame top level browser window.
tabWindow | Returns the handle for TabWindowClass window of the Internet Explorer 7 instance represented by the current Browser web macro object.
threadId | Returns the thread ID of the Internet Explorer window represented by the Browser IE macro object.
title | Returns the title of the web page.
topFrame | Returns a reference to the top Frame IE macro object.
topWindow | Returns the handle for IEFrame top window of the Internet Explorer 7 instance represented by the current Browser IE macro object.
url | Returns the URL for the current HTML document.
Constants
SHOW_IN_FOREGROUND Used by ShowBrowserWindow to bring the browser window in foreground. Not available in Open Twebst edition!
SHOW_HIDE Used by ShowBrowserWindow to hide the browser window. Not available in Open Twebst edition!
SHOW_MAXIMIZE Used by ShowBrowserWindow to maximize the browser window. Not available in Open Twebst edition!
SHOW_MINIMIZE Used by ShowBrowserWindow to minimize the browser window. Not available in Open Twebst edition!
SHOW_RESTORE Used by ShowBrowserWindow to restore the browser window. Not available in Open Twebst edition!
SHOW_VISIBLE Used by ShowBrowserWindow to make the browser window visible. Not available in Open Twebst edition!


IE9 macro recorder - automate existing instances of IWebBrowser2 in C#, VB.Net, JScript and VBScript

BrowserList - IE macro object

Not available in Open Twebst edition!
The BrowserList web macro object represents a collection of Browser objects. Each browser object in the list is connected to an Internet Explorer running instance. It provides properties to access Browser web automation objects in the collection.

  var browserListObj = coreObj.FindAllBrowsers(Search conditions);
Properties
core | Returns a reference to the parent Core object of the browser list.
item | Retrieves a Browser web macro object from the collection based on a given index.
length | Retrieves the number of Browser web automation objects in the collection.


IE9 macro recorder - automate IHTMLElement web control with C#, VBA and VB.Net

Element - IE macro object

The Element IE macro object represents a native Internet Explorer web control ( IHTMLElement ).
It provides methods and properties for:

  • searching other element objects inside the current element.
  • accessing parent and sibling elements
  • various actions on web controls like: Click, Highlight, InputText, SaveElementImage, Select.

  var elementObj = browserObj.FindElement(Search conditions);
  var elementObj = browserObj.FindAllElement(Search conditions)(index);
  var elementObj = frameObj.FindElement(Search conditions);
  var elementObj = frameObj.FindChildElement(Search conditions);
  var elementObj = frameObj.FindAllElements(Search conditions)(index);
  var elementObj = frameObj.FindChildrenElements(Search conditions)(index);
  var elementObj = elemObj.FindElement(Search conditions);
  var elementObj = elemObj.FindChildElement(Search conditions);
  var elementObj = elemObj.FindAllElements(Search conditions)(index);
  var elementObj = elemObj.FindChildrenElements(Search conditions)(index);
  var elementObj = coreObj.AttachToNativeElement(native element);
  var elementObj = elemObj.parentElement;
  var elementObj = elemObj.nextSiblingElement;
  var elementObj = elemObj.previousSiblingElement;
Methods
AddSelection | Add items to the current selection in HTML multiple selection list-box web controls.
AddSelectionRange | Add a range of items to the current selection in HTML multiple selection list-box web controls.
Check | Sets the checked state of a radio or checkbox control to true.
ClearSelection | Clears any selection in HTML combo-box or list-box web controls.
Click | Simulates a click on a IHTMLElement element.
FindAllElements | Searches in the current element, the list of all HTML elements that verify a list of search conditions.
FindChildElement | Searches in the current element, a direct HTML child element that verifies a list of search conditions.
FindChildrenElements | Searches in the current element, the list of direct HTML child elements that verify a list of search conditions.
FindElement | Searches in the current element, an HTML element that verifies a list of search conditions.
FindParentElement | Searches a parent element that matches a tag-name and verifies a list of search conditions.
GetAllSelectedOptions | Retrieves the collection of selected options in a combo-box or list-box control.
GetAttribute | Retrieves the value of the specified attribute.
Highlight | Highlights the element.
InputText | Simulates keystrokes in an HTML editable web control.
RemoveAttribute | Removes the given attribute from the object.
RightClick | Simulates a right click on a HTML element.
SaveElementImage | Save the screen image of the <img> element to a graphic file.
Select | Selects items in HTML drop-down or list-box web controls.
SelectRange | Selects a range of items in HTML multiple selection list-box web controls.
SetAttribute | Sets the value of the specified attribute.
Uncheck | Sets the checked state of a checkbox web control to false.
Properties
core | Returns a reference to the parent Core IE macro object of the element.
isChecked | Retrieves the state of a check box or radio button.
nativeElement | Returns a native HTML element ( IHTMLElement ) represented by the current web automation library Element object.
nextSiblingElement | Returns the next child of the parent for the object.
parentBrowser | Returns the parent Browser IE macro object of the current element.
parentElement | Returns the parent element object of the current element.
parentFrame | Returns the parent Frame IE macro object of the current element.
previousSiblingElement | Returns the previous child of the parent for the object.
selectedOption | Retrieves the selected option in a select object.
tagName | Retrieves the tag name of the object
text | Retrieves the text of the element.


Internet Explorer 10 macro - automate IHTMLElementCollection with VBA and C#

ElementList - IE macro object

This IE macro object represents a collection of Element web automation objects. Each web macro object in the collection represents a native Internet Explorer web control ( IHTMLElement ). It provides properties to access IE macro objects in the collection.

  var elementListObj = browserObj.FindAllElements(Search conditions);
  var elementListObj = frameObj.FindAllElements(Search conditions);
  var elementListObj = frameObj.FindChildrenElements(Search conditions);
  var elementListObj = elementObj.FindAllElements(Search conditions);
  var elementListObj = elementObj.FindChildrenElements(Search conditions);
Properties
core | Returns a reference to the parent Core IE macro object of the element list.
item | Retrieves an Element IE macro object from the collection based on a given index.
length | Retrieves the number of Element web macro objects in the collection.


Internet Explorer Macro - automate frame/iframe from Excel VBA

Frame - IE macro object

This IE macro object represents a native Internet Explorer window object ( IHTMLWindow2 ) corresponding to a frame or an iframe HTML element. It provides methods for searching other Frame or Element IE macro objects inside the current frame.

  var frame = browserObj.FindFrame(Search conditions);
  var frame = browserObj.FindAllFrames(Search conditions)(index);
  var frame = frameObj.FindFrame(Search conditions);
  var frame = frameObj.FindChildFrame(Search conditions);
  var frame = frameObj.FindAllFrames(Search conditions)(index);
  var frame = frameObj.FindChildrenFrames(Search conditions)(index);
  var frame = coreObj.AttachToNativeFrame(native frame);
  var frame = elemObj.parentFrame;
Methods
FindAllElements | Searches in the current frame, the collection of all web controls that verify a list of search conditions.
FindAllFrames | Searches in the current frame, the collection of all HTML frame and iframe objects that verify a list of search conditions.
FindChildElement | Searches in the current frame, a direct HTML child element that verifies a list of search conditions.
FindChildFrame | Searches in the current frame, a direct child frame or iframe that verifies a list of search conditions.
FindChildrenElements | Searches in the current frame, the collection of direct HTML child elements that verify a list of search conditions.
FindChildrenFrames | Searches inside a frame object, the collection of direct HTML frame and iframe objects that verify a list of search conditions.
FindElement | Searches in the current frame, an HTML element that verifies a list of search conditions.
FindFrame | Searches in the current frame, an HTML frame or iframe that verifies a list of search conditions.
Properties
core | Returns a reference to the parent Core web macro object of the frame.
document | Returns the native HTML document object ( IHTMLDocument2 ) of the current library frame object.
nativeFrame | Returns a native HTML frame or iframe object ( IHTMLWindow2 ) represented by the current web automation library frame object.
parentBrowser | Returns the parent Browser IE macro object of the current frame.
parentFrame | Returns the parent Frame web macro object of the current frame.


IE macro using Excel VBA - automate web page frame/iframe hierarchy

FrameList - IE macro object

Not available in Open Twebst edition!
This IE macro object represents a list of Frame web automation objects. Each frame object in the collection represents a native Internet Explorer frame/iframe object ( IHTMLWindow2 ). It provides properties to access the Frame web macro objects in the collection.

  var frameListObj = browserObj.FindAllFrames(Search conditions);
  var frameListObj = frameObj.FindAllFrames(Search conditions);
  var frameListObj = frameObj.FindChildrenFrames(Search conditions);
Properties
core | Returns a reference to the parent Core IE macro object of the frame list.
item | Retrieves a Frame IE macro object from the collection based on a given index.
length | Retrieves the number of Frame web macro objects in the collection.


IE9 tab automation - get programmatic control over IE tabs (TabWindowClass) with C#, VB.Net, VBA/Excel, JScript

activeTab - web automation property

Not available in Open Twebst edition!
This IE automation property retrieves a Browser object corresponding to the active tab inside a top level IE frame.

Applies to:
Browser
  var theTab = browserObj.activeTab;
Arguments:
None.
Remarks:
This property is available only for Internet Explorer 7 or higher.
This IE automation property returns a Browser web macro object corresponding to the active tab inside the top level IE frame window of the caling tab (the one for which activeTab property was called against).

The property throws a web automation exception if the version of Internet Explorer is not 7 or higher and the lastError property of the core object is set to INVALID_OPERATION_ERROR.
Example:

None.


IE6/IE7/IE8/IE8 web macro - fire HTML events to automate IHTMLElement with VBA/Excel, C# JScript and VBScript

asyncHtmlEvents - web automation property

Web macro property that determines whether HTML events will be fired up synchronously or asynchronously.

Applies to:
Core
  coreObj.asyncHtmlEvents = booleanValue;
Arguments:
None.
Remarks:
If booleanValue is false (the default value) then HTML events are generated synchronously and methods like Click, InputText are blocked until event handlers are executed. If booleanValue is true then HTML events are fired up asynchronously and methods above are executed in a non-blocking way. Click and InputText use either HTML events or hardware events according to useHardwareInputEvents property.

Setting asyncHtmlEvents to true makes sense when clicking a HTML element that triggers an window.alert, window.confirm or window.prompt pop-up, otherwise Click method is blocked until the pop-up is closed.
Example:

None.


IE9 automation - automatically close browser popups with .Net and VBA web macros

closeBrowserPopups - web automation property

IE automation property specifying if IE browser popups (security alerts, auto complete, errors) are automatically closed.

Applies to:
Core
  coreObj.closeBrowserPopups = true;
Arguments:
None.
Remarks:
The default value of this web automation property is false. If set to true, every web automation library method/property will first close browser popups.
Example:
// Automatically close IE popups (Security alerts, Errors and Auto complete) as they appear.
var core = new ActiveXObject("Twebst.Core");
core.closeBrowserPopups = true;


Automate Internet Explorer 6 - 10 protected mode on XP/Vista/Win7/Win8

core - web automation property

Returns a reference to the Core parent of the current object.

Applies to:
Browser, BrowserList, Element, ElementList, Frame, FrameList
  var c = obj.core;
Arguments:
None.
Remarks:
Returns the core object used to create directly or indirectly the current web automation object.
Example:
var coreObj    = new ActiveXObject("Twebst.Core");
var newBrowser = coreObj.StartBrowser("http://codecentrix.blogspot.com/");
WScript.Echo(newBrowser.core.lastError);


.Net IE automation of IHTMLDocument2 browser document

document - web automation property

Returns the native HTML document object ( IHTMLDocument2 ) from the current IE automation library Frame object.

Applies to:
Frame
  var doc = frameObj.document;
Arguments:
None.
Remarks:
This property gives access to all methods and properties of the HTML native document object.
Example:
var coreObj    = new ActiveXObject("Twebst.Core");
var newBrowser = coreObj.StartBrowser("http://www.codecentrix.com/");

var doc = newBrowser.topFrame.document;
WScrip.Echo("The document size is: " + doc.fileSize);


IE automation tool - programmatic control over the foreground IE instance (IWebBrowser2) from C# web macro code

foregroundBrowser - web automation property

Returns a web automation library Browser object attached to foreground Internet Explorer instance (the IWebBrowser2 with which the user is currently working).

Applies to:
Core
  var b = coreObj.foregroundBrowser;
Arguments:
None.
Remarks:
The property is null if no Internet Explorer browser is in foreground. The property returns a web automation Browser object that matches the search condition arguments and gets programmatic control over the IWebBrowser2 underlying IE native object. This IE automation property works for all Internet Explorer versions: IE6, IE7, IE8, IE9 and with IE protected mode on Windows XP, Vista and Win7.
Example:
// Make the foreground browser to navigate; start a new browser if there is no browser in foreground.
var coreObj = new ActiveXObject("Twebst.Core");
var b       = coreObj.foregroundBrowser;

if (b == null)
{
    // No foreground browser.

    b = coreObj.StartBrowser("http://www.codecentrix.com/");
}
else
{
    b.Navigate("http://www.codecentrix.com/");
}


IE testing and macros - programmatically find IE version.

IEVersion - web automation property

Web macro property that retrieves Internet Explorer version.

Applies to:
Core
  var version = coreObj.IEVersion;
Arguments:
None.
Remarks:
The Internet Explorer version is retrieved as a string formated as follows: 7.0.5730.11
Example:

None.
See also:
Core


Advanced C#/C++ IE automation - get Internet Explorer_Server window handle

ieWindow - web automation property

Not available in Open Twebst edition!
Returns the Win32 handle for Internet Explorer_Server window of the Internet Explorer instance represented by the current Browser object.

Applies to:
Browser
  var hwnd = browserObj.ieWnd;
Arguments:
None.
Remarks:
The Internet Explorer_Server window exists only if the browser displays an HTML document. The property is searching for window handle in the amount of time specified by loadTimeout property. If load timeout has expired and it was not possible to get a vadlid window handle, then lastError property is set to FAIL_ERROR and an IE automation exception is thrown. In case of an error the method throws a script exception and the lastError property of the core object is set as follows:
  • INVALID_ARG_ERROR: if invalid parameters are provided
  • FAIL_ERROR: in case of anohter error.
Example:
var coreObj    = new ActiveXObject("Twebst.Core");
var newBrowser = coreObj.StartBrowser("http://www.codecentrix.com/");
WScript.Echo(newBrowser.ieWindow);


IE6-IE9 web automation - test HTML check-boxes and radios state with C#, VBscript and JScript

isChecked - web automation property

Web automation property that retrieves the state of a check box or radio button web control.

Applies to:
Element
  var checked = elementObj.isChecked;
Arguments:
None.
Remarks:
Returns true if the checkbox or radio HTML element is checked, false otherwise. This web automation property is useful when testing the value of a check-box or radio. It can only be applied to automate <input type=radio> and <input type=checkbox> web controls, otherwise a web macro exception is thrown and the lastError property is set to INVALID_OPERATION_ERROR.
Example:
var coreObj    = new ActiveXObject("Twebst.Core");
var newBrowser = coreObj.StartBrowser("http://www.google.ro");
var radio      = newBrowser.FindElement("input radio");

if (!radio.isChecked)
{
    radio.Check();
}


VBScript IE automation - wait the browser page to finish loading

isLoading - web automation property

Web automation property that returns a boolean value indicating whether the browser is engaged in a navigation/loading operation.

Applies to:
Browser
  var loading = browserObj.isLoading;
Arguments:
None.
Remarks:
Returns true if the browser is engaged in a navigation or loading operation, false otherwise. In case of failure this property throws a web automation exception and the lastError property of the Core object is set to FAIL_ERROR or BROWSER_CONNECTION_LOST_ERROR.
Example:
var coreObj    = new ActiveXObject("Twebst.Core");
var newBrowser = coreObj.StartBrowser("http://www.codecentrix.com");

WScript.Sleep(100); // Give a chance to the browser to start navigation.
while (newBrowser.isLoading)
{
    // Wait the browser to load.

}

WScript.Echo(newBrowser.title);


Web automation software - register Twebst Automation Studio and go PRO to enjoy the full feature set

isRegistered - web automation property

Not available in Open Twebst edition!
Determines whether Twebst web automation software is currently registered.

Applies to:
Core
  var r = coreObj.isRegistered;
Arguments:
None.
Remarks:
The property is true if Twebst web automation software is registered, false otherwise. Registration is done on a per-user basis. A registration key is needed for every Windows user. When the product is registered, all PRO features are enabled and no demo warning dialog boxes are displayed.
Example:

None.
See also:
Core


IE7 to IE9 tabs automation - programmatically control tabs in C#, VB.Net, VBA/Excel

isTabActive - web automation property

Not available in Open Twebst edition!
IE automation property that retrieves the state of a tab window (active or inactive).

Applies to:
Browser
  var active = browserObj.isTabActive;
Arguments:
None.
Remarks:
This web automation property is available only for Internet Explorer 7 or higher.
This property returns true if the current tab is the active one or false otherwise.
Example:

None.


IE6, IE7, IE8 and IE9 browser macro - automate HTML element and frame collections in VBScript, C#, VB.Net, JScript

item - web automation property

Retrieves an Element, Frame or Browser object from a collection based on a given index.

Applies to:
BrowserList, ElementList, FrameList
  var obj = objList.item(index);
Arguments:
  • index is the zero based ordinal position of the object to be retrieved from the list of HTML elements/frames or browsers.
Remarks:
Because item is the default property of the list objects, it can be omitted. In this case, the index can applied directly to the list object (see the example bellow). If the index parameter is greater than the index of the last object in the list, a browser macro exception is thrown. In this case the lastError property of the Core object is set to INDEX_OUT_OF_BOUND_ERROR.
Example:
// Find all existing browsers using a regular expression.
// Display the title of  all browsers in the list.
var coreObj         = new ActiveXObject("Twebst.Core");
coreObj.loadTimeout = 0;
coreObj.useRegExp   = true;

var titles      = "";
var browserList = coreObj.FindAllBrowsers("title=.*");
for (i = 0; i < browserList.length; ++i)
{
    // The line bellow can be also writen like: titles += browserList(i).title;

    titles += browserList.item(i).title;
    titles += "\n";
}

WScript.Echo(titles);


Web Automation - error management

lastError - web automation property

Returns the error code for the last web automation operation.

Applies to:
Core
  var err = coreObj.lastError;
Arguments:
None.
Remarks:
All web automation methods and properties of the library modify the last error code. The error codes are constant properties of the Core object.
Example:

None.
See also:
Core


VBScript browser automation - automate HTML element and frame collections

length - web automation property

Retrieves the number of objects in a web automation collection.

Applies to:
BrowserList, ElementList, FrameList
  var len = listObj.length;
Arguments:
None.
Remarks:
Web automation collection objects use zero-based indexes. The last index in a list is length - 1.
Example:
// Display the number of the existing browser windows/tabs.
var coreObj         = new ActiveXObject("Twebst.Core");
coreObj.loadTimeout = 0;
coreObj.useRegExp   = true;

var browserList = coreObj.FindAllBrowsers("title=.*");
WScript.Echo(browserList.length);


VBScript, JScript web automation - set the timeout used to wait the browser page to finish loading

loadTimeout - web automation property

Web automation property that sets or retrieves the amount of time web automation methods wait the web page to load.

Applies to:
Core
  coreObj.loadTimeout = numericValue;
Arguments:
numericValue is the time to wait in milliseconds.
Remarks:

The default value of this web automation property is 60,000 milliseconds (one minute).
If loadTimeoutIsError property is true, then a web automation exception is thrown when load timeout expires in one of the methods bellow. In this case, the lastError property is set to LOAD_TIMEOUT_ERROR.
The property affects the following web automation methods: AddSelection, AddSelectionRange, FindAllBrowsers, FindElement, FindChildElement, FindFrame, FindChildFrame, FindAllElements, FindChildrenElements, FindAllFrames, FindChildrenFrames, FindParentElement, GetAllSelectedOptions, Select, selectedOption, SelectRange, WaitToLoad. These methods wait the web page to be completly loaded before they continue.

If loadTimeout is zero then find methods do not wait the page to complete and no script exception is thrown.

Example:

None.


Web page timeout management in JScript, VBScript and VBA browser web macro

loadTimeoutIsError - web automation property

Web automation property that enables or disables web macro exception raising when the loadTimeout has expired.

Applies to:
Core
  coreObj.loadTimeoutIsError = booleanValue;
Arguments:
None.
Remarks:
booleanValue is an expression evaluated to true or false.
If booleanValue is true, then a web macro exception is thrown when loadTimeout expires in one of the methods bellow.
The default value of the web automation property is true (by default web macro exceptions are thrown when loadTimeout expires).
The property affects the following methods: AddSelection, AddSelectionRange, FindAllBrowsers, FindElement, FindChildElement, FindFrame, FindChildFrame, FindAllElements, FindChildrenElements, FindAllFrames, FindChildrenFrames, FindParentElement, GetAllSelectedOptions, Select, selectedOption, SelectRange, WaitToLoad. When loadTimeout expires the lastError property is set to LOAD_TIMEOUT_ERROR.
Example:

None.


Internet Explorer Automation - error management

navigationError - web automation property

Internet Explorer automation property that returns the browser HTTP navigation error code.

Applies to:
Browser
  var err = browserObj.navigationError;
Arguments:
None.
Remarks:
If no HTTP error has occured the returned code is zero.
Example:
// Navigate to an invalid url and display the navigation error code.
var coreObj    = new ActiveXObject("Twebst.Core");
var newBrowser = coreObj.StartBrowser("a");

newBrowser.WaitToLoad();
WScript.Echo(newBrowser.navigationError);


IE automation in C# - get programmatic control over IWebBrowser2 MSHTML object

nativeBrowser - web automation property

Returns the native Internet Explorer browser object ( IWebBrowser2 ) represented by the current web automation library Browser object.

Applies to:
Browser
  var native = browserObj.nativeBrowser;
Arguments:
None.
Remarks:
With this IE automation property, get access to all methods and properties of the native IWebBrowser2 browser object from C#, VB.Net, VBScript web macros.
Example:
// Call StatusText native property.
var coreObj    = new ActiveXObject("Twebst.Core");
var newBrowser = coreObj.StartBrowser("http://www.codecentrix.com/");
var nativeBrws = newBrowser.nativeBrowser;

nativeBrws.StatusText = "Status bar modified by web macro!";


Internet Explorer Automation in C# - get programmatic control over IHTMLElement MSHTML object

nativeElement - web automation property

Returns a native HTML element ( IHTMLElement ) represented by the current web automation library Element object.

Applies to:
Element
  var native = elementObj.nativeElement;
Arguments:
None.
Remarks:
With this Internet Explorer automation property, get access to all methods and properties of the IHTMLElement native object from C#, VB.Net, VBScript web macros.
Example:
var coreObj    = new ActiveXObject("Twebst.Core");
var newBrowser = coreObj.StartBrowser("http://www.codecentrix.com/");

var e = newBrowser.FindElement("a", "text=Download");
var native = e.nativeElement;
WScript.Echo(native.outerHTML);


Internet Explorer Automation in .Net - get programmatic control over IHTMLWindow2 MSHTML frame/iframe object

nativeFrame - web automation property

Returns a native MSHTML frame or iframe object ( IHTMLWindow2 ) represented by the current web automation library Frame object.

Applies to:
Frame
  var native = frameObj.nativeFrame;
Arguments:
None.
Remarks:
With this Internet Explorer automation property, get access to all methods and properties of the IHTMLWindow2 native frame or iframe object.
Example:
var coreObj    = new ActiveXObject("Twebst.Core");
var newBrowser = coreObj.StartBrowser("http://codecentrix.blogspot.com/");
var frame      = newBrowser.topFrame.nativeFrame;

frame.navigate("http://www.codecentrix.com");


Internet Explorer Automation - browse DOM hierarchy, find the next IHTMLElement child

nextSiblingElement - web automation propety

Internet Explorer automation property that returns the next child of the parent for the object in the HTML DOM hierarchy.

Applies to:
Element
  var e = elementObj.nextSiblingElement;
Arguments:
None.
Remarks:
If the current element is the last child in DOM hierarchy, then null is returned.
Example:

None.


VBA IE automation - get IWebBrowser2 out of an IHTMLElement or IHTMLWindow2 frame/iframe in Excel

parentBrowser - web automation propety

IE automation property that returns the parent Browser object of the current Frame or Element.

Applies to:
Frame, Element
  var b = obj.parentBrowser;
Arguments:
None.
Remarks:
This web automation property can be useful if you already have a native frame or element and you need the parent Browser.
Example:
// You have a native element "native" and you need the parent Browser object.
var coreObj = new ActiveXObject("Twebst.Core");
var e       = coreObj.AttachToNativeElement(native);
var b       = e.parentBrowser;

b.Navigate("htp://www.codecentrix.com");


VBA IE automation - browse parent IHTMLElement in HTML DOM hierarchy

parentElement - web automation propety

IE automation property that returns the parent Element object of the current Element.

Applies to:
Element
  var e = elementObj.parentElement;
Arguments:
None.
Remarks:
If the current element has no parent IHTMLElement (it is the top element in the DOM hierarchy), then null is returned.
Example:
// Find the parent <form> element.
function FindParentForm(e)
{
    var f = e;
    while (true)
    {
        f = f.parentElement;
        if (f == null)
            break;

        if (f.nativeElement.tagName == "form")
            break;
    }

    return f;
}


IE automation in VBA - browse parent frame/iframe in HTML DOM hierarchy

parentFrame - web automation propety

IE automation property that returns the parent Frame object of the current Element or Frame. Returns null if the current frame/iframe has no parent because is the top frame in DOM hierarchy.

Applies to:
Element, Frame
  var f = obj.parentFrame;
Arguments:
None.
Remarks:
This IE automation property can be useful if you already have a native IHTMLElement object and you need the parent Frame.
Example:
// "e" is a native HTML element.
var coreObj            = new ActiveXObject("Twebst.Core");
var firstAnchorInFrame = coreObj.AttachToNativeElement(e).parentFrame.FindElement("a");


Internet Explorer Automation - browse DOM hierarchy, find the previous IHTMLElement child

previousSiblingElement - web automation propety

Internet Explorer automation property that returns the previous child of the parent for the object in the HTML DOM hierarchy.

Applies to:
Element
  var e = elementObj.previsouSiblingElement;
Arguments:
None.
Remarks:
If the current element is the first child in DOM hierarchy, then null is returned.
Example:

None.


Internet Explorer Automation in C# - get "Internet Explorer_Server" process ID

processId - web automation property

Not available in Open Twebst edition!
Internet Explorer automation property that returns the process ID of the Internet Explorer instance represented by the current Browser object.

Applies to:
Browser
  var pid = browserObj.processId;
Arguments:
None.
Remarks:
The process ID returned by this web automation property can be used in Search conditions for FindBrowser and FindAllBrowsers IE automation methods.
Example:
var coreObj    = new ActiveXObject("Twebst.Core");
var newBrowser = coreObj.StartBrowser("http://www.codecentrix.com/");
WScript.Echo(newBrowser.processId);


Web automation software - Twebst Automation Studio, IE9 macro recorder and web testing software

productName - web automation property

Returns the name of the installed Twebst web automation software.

Applies to:
Core
  var name = core.productName;
Arguments:
None.
Remarks:
The web automation software name depends on the currently installed Twebst Automation Studio edition:
  • Twebst Library Lite
  • Twebst Library Pro
Example:
var coreObj = new ActiveXObject("Twebst.Core");
var name    = coreObj.productName;
WScript.Echo(name);


Web automation software - IE8 macro recroder and web automation tool

productVersion - web automation property

Returns the version of the installed Twebst web automation software.

Applies to:
Core
  var name = core.productVersion;
Arguments:
None.
Remarks:
Returns the version formated as a string: major.minor
Example:
var coreObj = new ActiveXObject("Twebst.Core");
var name    = coreObj.productVersion;
WScript.Echo(name);


Web automation for AJAX web sites - set the timeout for searching HTML elements in DOM hierarchy

searchTimeout - web automation property

Web automation property that sets or retrieves the amount of time the automation library methods try to find HTML objects inside web pages DOM hierarchy.

Applies to:
Core
  coreObj.searchTimeout = numericValue;
Arguments:
numericValue is the time to wait in milliseconds.
Remarks:
The default value of this web automation property is 10,000 milliseconds (10 seconds).
The property affects the following web automation methods: AddSelection, AddSelectionRange, FindAllBrowsers, FindElement, FindChildElement, FindFrame, FindChildFrame, FindAllElements, FindChildrenElements, FindAllFrames, FindChildrenFrames, FindParentElement, GetAllSelectedOptions, Select, selectedOption, SelectRange. After the web page is completely loaded, these methods try to fo find HTML objects in the amount of time specified by the property. This property is useful for AJAX web sites with dynamically created web controls.
Example:

None.


IE automation - automate selecting options in HTML drop-down and list-box web controls

selectedOption - web automation propety

IE automation property that retrieves the selected option in a HTML drop-down / list-box web control.

Applies to:
Element
  var option = elementObj.selectedOption;
Arguments:
None.
Remarks:
If no option is selected then null is returned after searchTimeout has expired. It can be applied only to <select> objects, otherwise a web automation exception is thrown and the lastError property is set to INVALID_OPERATION_ERROR. In case of an error the method throws a script exception and the lastError property of the core object is set accordingly.

The time allocated for searching the selected option is specified by the searchTimeout property. If loadTimeout is not zero, then the method waits the browser objects to be completely loaded in the amount of time specified by the property. If the timeout has expired the lastError property is set to LOAD_TIMEOUT_ERROR. In this case, if loadTimeoutIsError property is true, then a web automation exception is thrown.
Example:
// Displays the selected option in a combo-box HTML control.
var coreObj = new ActiveXObject("Twebst.Core");
var browser = coreObj.StartBrowser("http://www.codecentrix.com/tests/qt3.htm");
var select  = browser.FindElement("select");

WScript.Echo(select.selectedOption.text);


Internet Explorer Macro - automate TabWindowClass in IE7, IE8 and IE9 with C#, VB.Net, VBA/Excel

tabList - web automation property

Not available in Open Twebst edition!
Connects a BrowserList IE macro object to all Browser objects inside IE7/IE8/IE9 tab windows (TabWindowClass).

Applies to:
Browser
  var tabs = browserObj.tabList;
Arguments:
None.
Remarks:
This property is available only for Internet Explorer 7 or higher.
This IE automation property returns a BrowserList macro object. It contains one Browser for each tab inside the main frame IE window corresponding to the calling Browser object. The calling tab (the one for which tabList property was called against) is placed in the first position inside the result BrowserList.

In case of an error the property throws a web automation exception and the lastError property of the core object is set as follows:
  • INVALID_OPERATION_ERROR: if the version of Internet Explorer is not 7 or higher.
  • INVALID_ARG_ERROR: if invalid parameters are provided.
  • FAIL_ERROR: in case of anohter error.
Example:
var coreObj  = new ActiveXObject("Twebst.Core");
var tabOne   = coreObj.StartBrowser("http://www.codecentrix.com/");
var tabTwo   = tabOne.OpenNewTab("http://www.google.com/");
var tabThree = tabOne.OpenNewTab("http://www.yahoo.com/");
var allTabs  = tabThree.tabList;

var text = "";
for (var i = 0; i < allTabs.length; ++i)
{
    text += allTabs.item(i).title + "\n";
}

WScript.Echo(text);


Internet Explorer Automation - automate IE tabs (TabWindowClass window handle) in C#, VB.Net and C++

tabWindow - web automation property

Not available in Open Twebst edition!
Returns the Win32 handle for TabWindowClass window of the Internet Explorer instance represented by the current Browser web automation object.

Applies to:
Browser
  var hwnd = browserObj.tabWindow;
Arguments:
None.
Remarks:
This property is available only for Internet Explorer 7 or higher.
In case of an error the method throws a web automation exception and the lastError property of the core object is set as follows:
  • INVALID_OPERATION_ERROR: if the version of Internet Explorer is not 7.
  • INVALID_ARG_ERROR: if invalid parameters are provided.
  • FAIL_ERROR: in case of anohter error.
Example:
var coreObj    = new ActiveXObject("Twebst.Core");
var newBrowser = coreObj.StartBrowser("http://www.codecentrix.com/");
WScript.Echo(newBrowser.tabWindow);


Web data extraction in C# - get the tagName of IHTMLElement

tagName - web automation propety

Retrieves the tag name of the web automation Element.

Applies to:
Element
  var t = elementObj.tagName;
Arguments:
None.
Remarks:
The returned tag name is a lowercase string.
Example:

None.


C# web data extraction with IE - scrap web content of IHTMLElement

text - web automation propety

Retrieves the text of the web automation Element object.

Applies to:
Element
  var t = elementObj.text;
Arguments:
None.
Remarks:
Unlike the native innerText property, the text property can be also used on some non-block HTML elements, like <input>.
  • For editable HTML controls, the text in the left side is returned.
  • For radio and checkbox controls, the text in the right side is returned.
  • For buttons, the text on the button is returned.
Example:
// Display the whole text of a HTML document.
var coreObj = new ActiveXObject("Twebst.Core");
var browser = coreObj.FindBrowser("url=http://www.codecentrix.com");
var body    = browser.FindElement("body");

WScript.Echo(body.text);


C# MSHTML programming - get "Internet Explorer_Server" thread ID

threadId - web automation property

Not available in Open Twebst edition!
Internet Explorer automation property that returns the thread ID of the Internet Explorer window represented by the current Browser object.

Applies to:
Browser
  var tid = browserObj.threadId;
Arguments:
None.
Remarks:
The returned thread ID can be used in Search conditions for FindBrowser and FindAllBrowsers web automation methods.
Example:
var coreObj    = new ActiveXObject("Twebst.Core");
var newBrowser = coreObj.StartBrowser("http://www.codecentrix.com/");
WScript.Echo(newBrowser.threadId);


C# MSHTML programming - extract the title of IHTMLDocument2

title - web automation property

Retrieves the title of the HTML document that is displayed in the header bar of the web page window.

Applies to:
Browser
  var t = browserObj.title;
Arguments:
None.
Remarks:
In case of failure this property throws a script exception and the lastError property of the Core object is set to FAIL_ERROR or BROWSER_CONNECTION_LOST_ERROR.
Example:
var coreObj    = new ActiveXObject("Twebst.Core");
var newBrowser = coreObj.StartBrowser("http://www.codecentrix.com/");
newBrowser.WaitToLoad();
WScript.Echo(newBrowser.title);


Internet Explorer Automation from Excel VBA - automate frame/iframe and bypass cross-domain scripting security restrictions

topFrame - web automation property

Retrieves the topmost ancestor Frame object in the frames DOM hierarchy of the Browser bypassing cross-domain scripting security restrictions.

Applies to:
Browser
  var frame = browserObj.topFrame;
Arguments:
None.
Remarks:
In case of failure this web automation property throws a script exception and the lastError property of the Core object is set to FAIL_ERROR.
Example:
var coreObj    = new ActiveXObject("Twebst.Core");
var newBrowser = coreObj.StartBrowser("http://codecentrix.blogspot.com/");
var frame      = newBrowser.topFrame;
frame.nativeFrame.navigate("http://www.codecentrix.com/");


C#/C++ IE6 - IE9 automation and MSHTML programming - get IEFrame Win32 window handle

topWindow - web automation property

Not available in Open Twebst edition!
Returns the Win32 handle for IEFrame top window of the Internet Explorer instance represented by the current Browser object.

Applies to:
Browser
  var hwnd = browserObj.topWindow;
Arguments:
None.
Remarks:
In case of an error the method throws a web macro exception and the lastError property of the core object is set as follows:
  • INVALID_ARG_ERROR: if invalid parameters are provided.
  • FAIL_ERROR: in case of anohter error.
Example:
var coreObj    = new ActiveXObject("Twebst.Core");
var newBrowser = coreObj.StartBrowser("http://www.codecentrix.com/");
WScript.Echo(newBrowser.topWindow);


C#/VB.Net MSHTML programming - extract the URL of IHTMLDocument2

url - web automation property

Returns the URL for the current IHTMLDocument2 document.

Applies to:
Browser
  var u = browserObj.url;
Arguments:
None.
Remarks:
In case of failure this web automation property throws a script exception and the lastError property of the Core object is set to FAIL_ERROR or BROWSER_CONNECTION_LOST_ERROR.
Example:
var coreObj    = new ActiveXObject("Twebst.Core");
var newBrowser = coreObj.StartBrowser("http://www.codecentrix.com/");
newBrowser.WaitToLoad();
WScript.Echo(newBrowser.url);


Internet Explorer Macro Recorder - fire HTML events on IHTMLElement to simulate users behavior

useHardwareInputEvents - web automation property

Sets or retrieves the type of input events used to simulate users actions on HTML elements.

Applies to:
Core
  coreObj.useHardwareInputEvents = booleanValue;
Arguments:
None.
Remarks:
booleanValue is an expression evaluated to true or false.
If booleanValue is false then HTML events are used to click on HTML elements, or to input text in editable controls. If booleanValue is true then hardware events are used. The browser window is put in foreground, then a hardware keyboard or mouse event is generated (using mouse_event or keybd_event Win32 API functions). The default value of the property is false (browser events are used by default).
The property affects the following web macro methods: Click and InputText.
Example:
// Click an element using hardware events.
var coreObj                    = new ActiveXObject("Twebst.Core");
coreObj.useRegExp              = true;
coreObj.useHardwareInputEvents = true;
coreObj.FindBrowser("url=codecentrix").FindElement("a", "text=Download").Click();


VBA/Excel IE automation - search HTML elements with regular expressions

useRegExp - web automation property

Not available in Open Twebst edition!
Enables or disables the use of regular expressions in Search conditions.

Applies to:
Core
  coreObj.useRegExp = booleanValue;
Arguments:
None.
Remarks:
booleanValue is an expression evaluated to true or false.
If booleanValue is true then regular expressions are used in Search conditions, otherwise they are not. The default value of this web automation property is false (by default regular expressions are not used). The property affects all web automation methods that take Search conditions as parameters.
Example:
// Find a browser that loaded a web page from the codecentrix domain.
var coreObj       = new ActiveXObject("Twebst.Core");
coreObj.useRegExp = true;
var browser       = coreObj.FindBrowser("url=codecentrix");
if (browser != null)
{
    browser.ShowBrowserWindow(browser.SHOW_IN_FOREGROUND);
}


Automate HTML <select> objects in IE9 browser - multiple selection list boxes

AddSelection - web automation method

Adds options to the current selection in HTML multiple selection list-box web controls.

Applies to:
Element
  elementObj.AddSelection(item_to_select);
Arguments:
  • item_to_select is the text or the ordinal position of the option to be added to list-box selection.
Remarks:
The input parameter can be:
  • a number that represents the zero-based ordinal position of the option to be added to selection.
  • a string that represents the text of the option to be added to selection. If useRegExp property is true, then all the options that match the input regular expression are added to selection.
If no option matches the input parameter, then a script exception is thrown and the lastError property is set to NOT_FOUND_ERROR
If the method is applied to an Element that is not a multiple selection list-box web control, then a script exception is thrown and the lastError property is set to INVALID_OPERATION_ERROR.

The time allocated for automating the options selection is specified by searchTimeout property. If loadTimeout is not zero, then the method waits the browser object to be completely loaded in the amount of time specified by the property. If the timeout has expired the lastError property is set to LOAD_TIMEOUT_ERROR. In this case, if loadTimeoutIsError property is true, then a script exception is thrown.
Example:
// Assume nativeList is a <select multiple> HTML element.
// Select the first two items in the multiple selection list-box control.
var coreObj = new ActiveXObject("Twebst.Core");
var list    = coreObj.AttachToNativeElement(nativeList);
list.Select(0);
list.AddSelection(1);


Browser automation - add a range of <option> objects to current selection in a HTML list-box web control

AddSelectionRange - web automation method

Add a range of options to the current selection in HTML multiple selection list-box web controls.

Applies to:
Element
  elementObj.AddSelectionRange(start_range, end_range);
Arguments:
  • start_range is the text or the ordinal position of the first option in the range to be added to selection.
  • end_range is the text or the ordinal position of the last option in the range to be added to selection.
Remarks:
The options between start_range and end_range are added to selection.
Each of the two input parameters can be:
  • a number that represents the zero-based ordinal position of the option to be the limit of the range.
  • a string that represents the text of the option to be the limit of the range.. If useRegExp property is true, then the limit of the range must match the regular expression represented by the input string parameter.

If the speciffied range is empty (no option matches the input parameters), then a script exception is thrown and the lastError property is set to NOT_FOUND_ERROR
If the method is applied to an Element that is not a HTML multiple selection list-box web control, then a script exception is thrown and the lastError property is set to INVALID_OPERATION_ERROR.

The time allocated for automating the options selection is specified by the searchTimeout property. If loadTimeout is not zero, then the method waits the browser objects to be completely loaded in the amount of time specified by the property. If the timeout has expired the lastError property is set to LOAD_TIMEOUT_ERROR. In this case, if loadTimeoutIsError property is true, then a script exception is thrown.
Example:
// Assume nativeList is a <select multiple> HTML element.
// Select the first three items in the multiple selection list-box control.
var coreObj = new ActiveXObject("Twebst.Core");
var list    = coreObj.AttachToNativeElement(nativeList);
list.Select(0);
list.AddSelectionRange(1, 2);


IE9 Automation - connect to existing instances of Internet Explorer

AttachToNativeBrowser - web automation method

Connects to an existing instance of IE6 - IE9 browser and creates a web automation library Browser object from a native Internet Explorer browser object.

Applies to:
Core
  var b = coreObj.AttachToNativeBrowser(nativeBrowserObject);
Arguments:
  • nativeBrowserObject is a native Internet Explorer browser object.
Remarks:
Returns a Browser object. The nativeBrowserObject parameter is a native Internet Explorer browser object ( IWebBrowser2 ). It could be obtained using other ways than Twebst web automation library features. It could be also obtained by using nativeBrowser property. This method is useful if you already have a native Internet Explorer browser instance and you want to use it as a web automation Browser object.
Example:
// Start an Internet Explorer object and attach a Browser object to it.
// Navigate using the library Browser object.
var internetExplorer     = new ActiveXObject("InternetExplorer.Application");
internetExplorer.Visible = true;

var coreObj         = new ActiveXObject("Twebst.Core");
var attachedBrowser = coreObj.AttachToNativeBrowser(internetExplorer);
attachedBrowser.Navigate("www.codecentrix.com");


IE Automation Library - get full programmatic control over HTML elements

AttachToNativeElement - web automation method

Automates an existing instance of IE6 - IE9 browser and creates a web automation library Element object from a native Internet Explorer web object.

Applies to:
Core
  var e = coreObj.AttachToNativeElement(nativeElementObject);
Arguments:
  • nativeElementObject is a native Internet Explorer element object.
Remarks:
Returns an Element library object. The nativeElementObject parameter is a native Internet Explorer HTML element ( IHTMLElement ). It could be obtained using other ways than Twebst web automation library features. It could be also obtained by using nativeElement property. This method is useful if you already have a native Internet Explorer web control and you want to use it as a library Element object.
Example:
// Start an Internet Explorer object.
// Get the body native element and attach to it.
// Use the attached library Element object.
var internetExplorer     = new ActiveXObject("InternetExplorer.Application");
internetExplorer.Visible = true;

var coreObj         = new ActiveXObject("Twebst.Core");
var body            = internetExplorer.Document.body;
var attachedElement = coreObj.AttachToNativeElement(body);

attachedElement.parentBrowser.Navigate("www.codecentrix.com");


IE9 Macro - connect to an existing frame/iframe DOM hierarchy

AttachToNativeFrame - web automation method

Connects to an existing IE6/IE7/IE8/IE9 browser instance and creates a web macro Frame object from a native Internet Explorer window object.

Applies to:
Core
  var f = coreObj.AttachToNativeFrame(nativeWindowObject);
Arguments:
  • nativeWindowObject is a native Internet Explorer window object.
Remarks:
Returns a Frame web automation object. The nativeWindowObject parameter is a native Internet Explorer window object ( IHTMLWindow2 ). It could be obtained using other ways than Twebst web automation library features. It could be also obtained by using nativeFrame property. This method is useful if you need to automate a native frame/iframe DOM hierarchy in an existing IE6/IE7/IE8/IE9 browser instance.
Example:
// Start an Internet Explorer object.
// Get the top window native object and attach to it.
// Use the attached library Frame object.
var internetExplorer     = new ActiveXObject("InternetExplorer.Application");
internetExplorer.Visible = true;

var coreObj        = new ActiveXObject("Twebst.Core");
vartopWindow      = internetExplorer.Document.parentWindow;
var attachedWindow = coreObj.AttachToNativeFrame(topWindow);

attachedWindow.parentBrowser.Navigate("www.codecentrix.com");


IE6/IE7/IE8/IE9 add-ons/extensions development with Twebst Web Automation Library

AttachToWnd - web automation method

Not available in Open Twebst edition!
Creates a web automation library Browser object from a 'Internet Explorer_Server', 'IEFrame' or 'TabWindowClass' window handle.

Applies to:
Core
  var b = coreObj.AttachToWnd(hWnd);
Arguments:
  • hWnd is a Win32 API window handle.
Remarks:
Returns a Browser web automation library object. The hWnd parameter is the handle of a Internet Explorer_Server, IEFrame or TabWindowClass window of Internet Explorer browser. It could be obtained using other ways than Twebst web automation library features. It could be also obtained by using ieWindow, tabWindow or topWindow properties. This method is useful when you need to automate an existing IE browser instance for which you have a Win32 API window handle.
Example:
// hwnd is a valid handle of a 'Internet Explorer_Server', 'IEFrame' or 'TabWindowClass' window inside IE.
var hwnd    = 0x1C05B8;
var core    = new ActiveXObject("Twebst.Core");
var browser = core.AttachToWnd(hwnd);

browser.Navigate("http://www.codecentrix.com/");


Automating a checkbox/radio web control in Internet Explorer 9

Check - web automation method

Sets the checked state of a radio or checkbox web control to true. All necessary HTML events are fired up to simulate user's behavior

Applies to:
Element
  radioOrCheckboxObj.Check();
Arguments:
None.
Remarks:
The method selects a checkbox or radio by simulating a click on the HTML web control using hardware or Internet Explorer events, depending on useHardwareInputEvents property. If the element is already checked, the method returns immediately. The method can only be applied to <input type=radio> and <input type=checkbox> elements, otherwise a web macro exception is thrown and the lastError property is set to INVALID_OPERATION_ERROR.
Example:
var coreObj    = new ActiveXObject("Twebst.Core");
var newBrowser = coreObj.StartBrowser("http://www.google.ro");
var radio      = newBrowser.FindElement("input radio");

if (!radio.isChecked)
{
    radio.Check();
}


Combo-box/list-box web control automation in IE browser

ClearSelection - web automation method

Web macro method that clears any selection in HTML combo-box (drop-down) or list-box web controls.

Applies to:
Element
  elementObj.ClearSelection();
Arguments:
None.
Remarks:
If the method is applied to an Element that is not a combo-box or list-box web control, then a web macro exception is thrown and the lastError property is set to INVALID_OPERATION_ERROR.
Example:
// Assume nativeList is a <select multiple> HTML element.
// Clear the selection in the multiple selection list-box control.
var coreObj = new ActiveXObject("Twebst.Core");
var list    = coreObj.AttachToNativeElement(nativeList);
list.ClearSelection();


Web Automation - simulate click on web controls (anchors, buttons, checkboxes, radios, submit-reset button, images)

Click - web automation method

Web automation method that simulates a click on a HTML web control.

Applies to:
Element
  elementObj.Click();
Arguments:
None.
Remarks:
This web automation method simulates a click on any HTML element using hardware or Internet Explorer events, depending on useHardwareInputEvents property. All necessary HTML events are fired up to simulate user's behavior (onmouseover, onmousemove, onmousedown, onbeforeactivate, onactivate, onfocusin, onfocus, onmouseup, onclick).
Example:
var coreObj = new ActiveXObject("Twebst.Core");
var browser = coreObj.StartBrowser("http://www.codecentrix.com/");

var element = browser.FindElement("a", "text=Download");
element.Click();


Web macro - programmatically close IE6/IE7/IE8/IE9 window

Close - web automation method

Closes the Internet Explorer instance represented by the Browser web automation library object.

Applies to:
Browser
  browserObj.Close();
Arguments:
None.
Remarks:
The method throws a web macro exception if the browser instance can not be closed (for example, if the browser is already closed). In this case the lastError property of the Core object is set to FAIL_ERROR or BROWSER_CONNECTION_LOST_ERROR.
Example:
var coreObj    = new ActiveXObject("Twebst.Core");
var newBrowser = coreObj.StartBrowser("http://codecentrix.blogspot.com/");
newBrowser.Close();


IE macro - automatically close window.alert / window.confirm popup windows

ClosePopup - web automation method

Closes a window.alert or a window.confirm popup window in Internet Explorer instance represented by the Browser web automation library object.

Applies to:
Browser
  var text = browserObj.ClosePopup("popup_text", "button");
Arguments:
  • popup_text specifies the text of the IE popup window to be found. This parameter is affected by useRegExp property
  • button specifies the button to press; it is the button text or the button zero-based index order.
Remarks:
If popup_text parameter is emtpy then any window.alert / window.confirm popup window will be closed. This web automation method returns the text displayed by the pop-up window. The time allocated for searching the popup is specified by the searchTimeout property. The method throws a web macro exception if the popup or the button is not found. In this case the lastError property of the Core object is set to FAIL_ERROR.
Example:
var core    = new ActiveXObject("Twebst.Core");
var browser = core.StartBrowser("http://www.codecentrix.com/tests/testPopups.htm");

// Use hardware events otherwise Click will be blocked until the popup is close!

core.useHardwareInputEvents = true;
browser.FindElement("input button", "text=Alert").Click();
browser.ClosePopup("Alert text", "OK");


IE automation - programatically close window.prompt web popup windows in C#, VB.Net and VBScript

ClosePrompt - web automation method

Closes a window.prompt popup window in Internet Explorer instance represented by the Browser web automation library object.

Applies to:
Browser
  var text = browserObj.ClosePrompt("popup_text", "value", "button");
Arguments:
  • popup_text specifies the text of the IE popup window to be found. This parameter is affected by useRegExp property
  • value specifies the text used to fill out the edit field inside prompt popup window.
  • button specifies the button to press; it is the button text or the button zero-based index order.
Remarks:
If popup_text parameter is emtpy then any window.prompt popup window will be closed. This web automation method returns the text displayed by the pop-up window. The time allocated for searching the popup is specified by the searchTimeout property. The method throws a web macro exception if the popup or the button is not found. In this case the lastError property of the Core object is set to FAIL_ERROR.
Example:
var core    = new ActiveXObject("Twebst.Core");
var browser = core.StartBrowser("http://www.codecentrix.com/tests/testPopups.htm");

// Use hardware events otherwise Click will be blocked until the popup is close!

core.useHardwareInputEvents = true;
browser.FindElement("input button", "text=Prompt").Click();
browser.ClosePopup("Prompt text", "new value", "OK");


IE6/IE8/IE8/IE9 Macro - connect to all open instances of Internet Explorer

FindAllBrowsers - web automation method

Not available in Open Twebst edition!
Connects a BrowserList IE automation object to multiple instances of Internet Explorer browser that verify a list of Search Conditions.

Applies to:
Core
  var browserList = coreObj.FindAllBrowsers(Search conditions);
Arguments:
This method accepts a variable number of Search Condition arguments. The following attributes are accepted in search conditions:
  • TITLE condition on the title of the browser window
  • URL condition on the url of the web page
  • TID condition on the thread id of the Internet ExplorerInternet Explorer window
  • PID condition on the process id of the Internet Explorer instance
  • APP the name of the application hosting the Internet Explorer web control
Remarks:
The method returns a IE automation library BrowserList object. The Browser objects in the list match the search condition arguments. If no browser verifies the search conditions, then an empty list is returned.
In case of an error the method throws an IE macro exception and the lastError property of the core object is set as follows:
  • INVALID_ARG_ERROR: if invalid parameters are provided
  • FAIL_ERROR: in case of anohter error.

If loadTimeout is not zero, then the method waits all browser objects in the list to be completely loaded in the amount of time specified by the property. If the timeout has expired the lastError property is set to LOAD_TIMEOUT_ERROR. In this case, if loadTimeoutIsError property is true, then a web macro exception is thrown.
The search is affected by useRegExp property.

APP attribute is not affected by useRegExp property and is case insensitive. The default value is iexplore.exe and * stands for any application (including IE).
Example:
// Find all browsers by using a regular expression.
// Do not wait the browsers in the list to be completely loaded.
// Close all the browsers in the list.
var coreObj         = new ActiveXObject("Twebst.Core");
coreObj.loadTimeout = 0;
coreObj.useRegExp   = true;

var browserList = coreObj.FindAllBrowsers("title=.*");
for (i = 0; i < browserList.length; ++i)
{
    browserList(i).nativeBrowser.Quit();
}


IE Macro - automate IHTMLElementCollection with C#, VB.Net, C++

FindAllElements - web automation method

Searches inside a container web automation object, the collection of all HTML elements that match a tag-name and verifies a list of Search Conditions.

Applies to:
Browser, Frame, Element
  var elementList = obj.FindAllElements("tag_name", Search conditions);
Arguments:
This method accepts a variable number of Search Condition arguments. Any HTML attribute is accepted in search conditions. Text is also accepted as attribute in search conditions, in this case the text of the HTML element is used in search. If no search condition is provided, then the collection of all elements that match the tag_name is returned.
  • tag_name is the HTML tag of the elements to be found.
Remarks:
The method returns an ElementList web automation object containing HTML elements that match the search condition arguments and have the specified tag_name. If no element verifies the search conditions, then an empty list is returned. In case of an error the method throws a web macro exception and the lastError property of the core object is set as follows:
  • INVALID_ARG_ERROR: if invalid parameters are provided
  • BROWSER_CONNECTION_LOST_ERROR: if the browser was closed.
  • FAIL_ERROR: in case of anohter error.

The time allocated for search is specified by the searchTimeout property. The search is affected by useRegExp property. If loadTimeout is not zero, then the method waits the browser objects to be completely loaded in the amount of time specified by the property. If the timeout has expired the lastError property is set to LOAD_TIMEOUT_ERROR. In this case, if loadTimeoutIsError property is true, then a script exception is thrown.

If the container object is a Browser, then the method searches the elements in all the frame and iframe DOM hierarchy of the browser. If the container object is a Frame, then the method searches the elements in all the frame and iframe DOM hierarchy of the container frame. If the container object is an Element, then the method searches the elements in all HTML DOM hierarchy of the container.

The target HTML elements can be inside frames/iframes loaded from various domains. Twebst Web Automation Library bypass all cross-frame scripting security restrictions (see: When IHTMLWindow2::get_document returns E_ACCESSDENIED and When IHTMLWindow2.document throws UnauthorizedAccessException).
Example:
// Display all the links in a web page.
var coreObj = new ActiveXObject("Twebst.Core");
var browser = coreObj.StartBrowser("http://www.codecentrix.com/");

var textToDisplay = "";
var anchorList    = browser.FindAllElements("a");
for (i = 0; i < anchorList.length; ++i)
{
    textToDisplay += anchorList(i).nativeElement.innerText + "\n";
}
WScript.Echo(textToDisplay);


IE9 Macro - automate frame/iframe DOM hierarchy in C#, VB.Net

FindAllFrames - web automation method

Not available in Open Twebst edition!
Searches inside a web automation container object, the list of all HTML frame and iframe objects that verify a list of search conditions.

Applies to:
Browser, Frame
  var frameList = obj.FindAllFrames(Search conditions);
Arguments:
This method accepts a variable number of Search Condition arguments. If no search condition is provided, then the collection of all frame and iframe objects in the container is returned. Any HTML frame or iframe attribute is accepted in search conditions.
Remarks:
The method returns a FrameList web automation object containing frame and iframe objects that match the search condition arguments. If no frame and iframe object verifies the search conditions, then an empty list is returned.
In case of an error the method throws an IE macro exception and the lastError property of the core object is set as follows:
  • INVALID_ARG_ERROR: if invalid parameters are provided
  • BROWSER_CONNECTION_LOST_ERROR: if the browser was closed.
  • FAIL_ERROR: in case of anohter error.

The time allocated for search is specified by the searchTimeout property. The search is affected by useRegExp property. If loadTimeout is not zero, then the method waits the browser objects to be completely loaded in the amount of time specified by the property. If the timeout has expired the lastError property is set to LOAD_TIMEOUT_ERROR. In this case, if loadTimeoutIsError property is true, then a IE macro exception is thrown.

If the container object is a Browser, then the method searches the frames in all the frame and iframe DOM hierarchy of IE browser. If the container object is a Frame, then the method searches the frames in all the frame and iframe DOM hierarchy of the container Frame.
Example:
var coreObj    = new ActiveXObject("Twebst.Core");
var browser    = coreObj.StartBrowser("http://www.codecentrix.com/");

var textToDisplay = "";
var frameList     = browser.FindAllFrames();
for (i = 0; i < frameList.length; ++i)
{
    textToDisplay += frameList(i).nativeFrame.document.URL + "\n";
}
WScript.Echo(textToDisplay);


Internet Explorer Automation Tool - connect to running IE instances (IWebBrowser2) from web macro code

FindBrowser - web automation method

Connects a web automation Browser to an existing instance of Internet Explorer object ( IWebBrowser2 ) that verifies a list of Search Conditions.

Applies to:
Core
  var b = coreObj.FindBrowser(Search conditions);
Arguments:
This method accepts a variable number of Search Condition arguments. The following attributes are accepted in search conditions:
  • TITLE condition on the title of the browser window
  • URL condition on the url of the web page
  • TID condition on the thread id of the Internet Explorer window
  • PID condition on the process id of the Internet Explorer instance
  • APP the name of the application hosting the Internet Explorer web control
Remarks:
The method returns a web automation Browser object that matches the search condition arguments and gets programmatic control over the IWebBrowser2 underlying IE native object. If no browser verifies the search conditions, then null is returned.
In case of an error the method throws a web macro exception and the lastError property of the core object is set as follows:
  • INVALID_ARG_ERROR: if invalid parameters are provided
  • FAIL_ERROR: in case of anohter error.

The time allocated for search is specified by the searchTimeout property. The search is affected by useRegExp property.
APP attribute is not affected by useRegExp property and is case insensitive. The default value is iexplore.exe and * stands for any application (including IE). This IE automation method works for all Internet Explorer versions: IE6, IE7, IE8, IE9 and with IE protected mode on Windows XP, Vista and Win7.
Example:
var coreObj = new ActiveXObject("Twebst.Core");
var browser = coreObj.FindBrowser("URL=http://www.codecentrix.com/");

// If the browser is found, bring the brower window in foreground.
if (browser != null)
{
    browser.ShowBrowserWindow(browser.SHOW_IN_FOREGROUND);
}


Internet Explorer 10 Macro - automating IHTMLElement web controls in C# and VB.Net

FindChildElement - web automation method

Searches inside a container object, a direct HTML child element that matches a tag-name and verifies a list of Search Conditions.

Applies to:
Frame, Element
  var e = obj.FindChildElement("tag_name", Search conditions);
Arguments:
This method accepts a variable number of Search Condition arguments. Any HTML attribute is accepted in search conditions. text is also accepted as attribute in search conditions, in this case the text of the HTML element is used in search. A special zero-based index attribute is available in search condition specifying the ordinal position in the collection of objects generated by the remaining search conditions. If no search condition is provided, then the first element that matches the tag_name is returned.
  • tag_name is the HTML tag of the element to be found.
Remarks:
The method returns a web automation Element object that matches the search condition arguments and has the specified tag_name. It provides programmatic control over the underlying IHTMLElement native object exposed by IE browser. If no element verifies the search conditions, then null is returned.
In case of an error the method throws a macro exception and the lastError property of the core object is set as follows:
  • INVALID_ARG_ERROR: if invalid parameters are provided
  • BROWSER_CONNECTION_LOST_ERROR: if the browser was closed.
  • FAIL_ERROR: in case of anohter error.

The time allocated for search is specified by the searchTimeout property. The search is affected by useRegExp property. If loadTimeout is not zero, then the method waits the browser objects to be completely loaded in the amount of time specified by the property. If the timeout has expired the lastError property is set to LOAD_TIMEOUT_ERROR. In this case, if loadTimeoutIsError property is true, then a script exception is thrown.

If the container object is a macro Frame object, then the method searches the element in the HTML document associated with the frame. If the container object is a macro Element object, then the method searches the element among the direct children elements of the container element.
Example:
var coreObj = new ActiveXObject("Twebst.Core");
var browser = coreObj.StartBrowser("http://www.codecentrix.com/");

var element = browser.topFrame.FindChildElement("a", "text=Download");
element.Click();


IE6- IE9 macro recorder - IHTMLWindow2 automating frame/iframe DOM hierarchy in .Net

FindChildFrame - web automation method

Searches inside a web automation Frame object, a direct child frame or iframe that verifies a list of Search Conditions.

Applies to:
Frame
  var f = frame.FindChildFrame(Search conditions);
Arguments:
This method accepts a variable number of Search Condition arguments. If no search condition is provided, then the first frame in the container is returned. Any HTML frame or iframe attribute is accepted in search conditions. A special zero-based index attribute is allowed in search condition specifying the ordinal position in the collection of objects generated by the remaining search conditions.
Remarks:
The method returns a Frame web automation object that matches the search condition arguments and provides programmatic control over the underlying IHTMLWindow2 native object exposed by IE browser. If no frame verifies the search conditions, then null is returned.
In case of an error the method throws a script exception and the lastError property of the core object is set as follows:
  • INVALID_ARG_ERROR: if invalid parameters are provided
  • BROWSER_CONNECTION_LOST_ERROR: if the browser was closed.
  • FAIL_ERROR: in case of anohter error.

The time allocated for search is specified by the searchTimeout property. The search is affected by useRegExp property. If loadTimeout is not zero, then the method waits the browser objects to be completely loaded in the amount of time specified by the property. If the timeout has expired the lastError property is set to LOAD_TIMEOUT_ERROR. In this case, if loadTimeoutIsError property is true, then a script exception is thrown.

The method searches only the direct children frames of the container frame.
Example:

None.


Automate IE9 web testing with Twebst Web Automation Library

FindChildrenElements - web automation method

Searches inside a container object, the list of direct child elements that match a tag-name and verifies a list of Search Conditions.

Applies to:
Frame, Element
  var elementList = obj.FindChildrenElements("tag_name", Search conditions);
Arguments:
This method accepts a variable number of Search Condition arguments. Any HTML attribute is accepted in search conditions. Text is also accepted as attribute in search conditions, in this case the text of the HTML element is used in search. If no search condition is provided, then the collection of all direct child elements that match the tag_name is returned.
  • tag_name is the HTML tag of the elements to be found.
Remarks:
The method returns an ElementList web automation object containing elements that match the search condition arguments and have the specified tag_name. If no element verifies the search conditions, then an empty list is returned.
In case of an error the method throws a script exception and the lastError property of the core object is set as follows:
  • INVALID_ARG_ERROR: if invalid parameters are provided
  • BROWSER_CONNECTION_LOST_ERROR: if the browser was closed.
  • FAIL_ERROR: in case of anohter error.

The time allocated for search is specified by the searchTimeout property. The search is affected by useRegExp property. If loadTimeout is not zero, then the method waits the browser objects to be completely loaded in the amount of time specified by the property. If the timeout has expired the lastError property is set to LOAD_TIMEOUT_ERROR. In this case, if loadTimeoutIsError property is true, then a script exception is thrown.

If the container object is a Frame, then the method searches the elements in the HTML document associated with the frame. If the container object is an Element, then the method searches the elements among the direct children elements of the container element.
Example:
// Display all the links in the <body> HTML element.
var coreObj = new ActiveXObject("Twebst.Core");
var browser = coreObj.StartBrowser("http://www.codecentrix.com/");

var textToDisplay = "";
var anchorList    = browser.FindElement("body").FindChildrenElements("a");
for (i = 0; i < anchorList.length; ++i)
{
    textToDisplay += anchorList(i).nativeElement.innerText + "\n";
}
WScript.Echo(textToDisplay);


IE9 macros - automate IHTMLWindow2 frame/iframe DOM hierarchy with C#

FindChildrenFrames - web automation method

Not available in Open Twebst edition!
Searches inside a frame object, the list of direct children frame and iframe objects that verify a list of search conditions.

Applies to:
Frame
  var frameList = frameObj.FindChildrenFrames(Search conditions);
Arguments:
This method accepts a variable number of Search Condition arguments. If no search condition is provided, then the collection of direct frame and iframe objects in the frame container is returned. Any HTML frame or iframe attribute is accepted in search conditions.
Remarks:
The method returns a FrameList object containing direct child frame and iframe objects that match the search condition arguments. If no frame and iframe object verifies the search conditions, then an empty list is returned.
In case of an error the method throws a script exception and the lastError property of the core object is set as follows:
  • INVALID_ARG_ERROR: if invalid parameters are provided
  • BROWSER_CONNECTION_LOST_ERROR: if the browser was closed.
  • FAIL_ERROR: in case of anohter error.

The time allocated for search is specified by the searchTimeout property. The search is affected by useRegExp property. If loadTimeout is not zero, then the method waits the browser objects to be completely loaded in the amount of time specified by the property. If the timeout has expired the lastError property is set to LOAD_TIMEOUT_ERROR. In this case, if loadTimeoutIsError property is true, then a script exception is thrown.

The method searches the frames among the direct child frame and iframe objects in the container frame.
Example:

None.


.Net web automation of IHTMLElement in IE6, IE7/IE8/IE9 protected mode

FindElement - web automation method

Connects a web automation Element to an IHTMLElement that matches a tag-name and verifies a list of Search Conditions.

Applies to:
Browser, Frame, Element
  var e = obj.FindElement("tag_name", Search conditions);
Arguments:
This method accepts a variable number of Search Condition arguments. Any HTML attribute is accepted in search conditions. Text is also accepted as attribute in search conditions, in this case the text of the HTML element is used in search. A special zero-based index attribute is available in search condition specifying the ordinal position in the collection of objects generated by the remaining search conditions. If no search condition is provided then the first element that matches the tag_name is returned.
  • tag_name is the HTML tag of the element to be found.
Remarks:
The method returns an Element IE automation object that matches the search condition arguments and has the specified tag_name. It provides programmatic control over the underlying IHTMLElement native object exposed by IE browser. If no element verifies the search conditions, then null is returned.
In case of an error the method throws a script exception and the lastError property of the core object is set as follows:
  • INVALID_ARG_ERROR: if invalid parameters are provided
  • BROWSER_CONNECTION_LOST_ERROR: if the browser was closed.
  • FAIL_ERROR: in case of anohter error.

The time allocated for search is specified by the searchTimeout property. The search is affected by useRegExp property. If loadTimeout is not zero, then the method waits the browser objects to be completely loaded in the amount of time specified by the property. If the timeout has expired the lastError property is set to LOAD_TIMEOUT_ERROR. In this case, if loadTimeoutIsError property is true, then a IE macro exception is thrown.

If the container object is a Browser, then the method searches the element in all the frame and iframe DOM hierarchy of the browser. If the container object is a Frame, then the method searches the element in all the frame and iframe DOM hierarchy of the container frame. If the container object is an Element, then the method searches the element in all HTML DOM hierarchy of the container.

The target HTML element can be inside frames/iframes loaded from various domains. Twebst Web Automation Library bypass all cross-frame scripting security restrictions (see: When IHTMLWindow2::get_document returns E_ACCESSDENIED and When IHTMLWindow2.document throws UnauthorizedAccessException).
Example:
var coreObj = new ActiveXObject("Twebst.Core");
var browser = coreObj.StartBrowser("http://www.codecentrix.com/");

var element = browser.FindElement("a", "text=Download");
element.Click();


IE automation - automate IHTMLWindow2 frame/iframe from C#

FindFrame - web automation method

Searches inside a container object, an HTML frame or iframe that verifies a list of Search Conditions.

Applies to:
Browser, Frame
  var f = obj.FindFrame(Search conditions);
Arguments:
This method accepts a variable number of Search Condition arguments. If no search condition is provided, then the first frame in the container is returned. Any HTML frame or iframe attribute is accepted in search conditions. A special zero-based index attribute is allowed in search condition specifying the ordinal position in the collection of objects generated by the remaining search conditions.
Remarks:
The method returns a web automation Frame object that matches the search condition arguments and provides programmatic control over the underlying IHTMLWindow2 native object exposed by IE browser. If no frame verifies the search conditions, then null is returned.
In case of an error the method throws a script exception and the lastError property of the core object is set as follows:
  • INVALID_ARG_ERROR: if invalid parameters are provided
  • BROWSER_CONNECTION_LOST_ERROR: if the browser was closed.
  • FAIL_ERROR: in case of anohter error.

The time allocated for search is specified by the searchTimeout property. The search is affected by useRegExp property. If loadTimeout is not zero, then the method waits the browser objects to be completely loaded in the amount of time specified by the property. If the timeout has expired the lastError property is set to LOAD_TIMEOUT_ERROR. In this case, if loadTimeoutIsError property is true, then a script exception is thrown.

If the container object is a Browser, then the method searches the frame in all the <frame> and <iframe> hierarchy of the browser. If the container object is a Frame, then the method searches the frame in all the <frame> and <iframe> hierarchy of the container frame.
Example:
var coreObj    = new ActiveXObject("Twebst.Core");
var browser    = coreObj.StartBrowser("http://codecentrix.blogspot.com/");
var firstFrame = browser.FindFrame();
firstFrame.nativeFrame.navigate("http://www.codecentrix.com");


IE9 automation - automate modal HTML dialog boxes opened by showModalDialog

FindModalHtmlDialog - web automation method

Connects a Frame IE automation object to a modal dialog box that displays a HTML document (see showModalDialog).

Applies to:
Browser
  var modalFrame = browser.FindModalHtmlDialog();
Arguments:
None.
Remarks:
The method returns a Frame IE automation object corresponding to a HTML modal dialog box created by showModalDialog method. If no modal HTML dialog box is found, then null is returned. Internet Explorer pop-up blocker may block HTML dialogs. In case of an error the method throws a script exception and the lastError property of the core object is set as follows:
  • BROWSER_CONNECTION_LOST_ERROR: if the browser was closed.
  • FAIL_ERROR: in case of anohter error.

The time allocated for search is specified by the searchTimeout property. If loadTimeout is not zero, then the method waits the browser objects to be completely loaded in the amount of time specified by the property. If the timeout has expired the lastError property is set to LOAD_TIMEOUT_ERROR. In this case, if loadTimeoutIsError property is true, then a IE macro exception is thrown.
Example:
var coreObj = new ActiveXObject("Twebst.Core");
var browser = coreObj.StartBrowser("http://www.codecentrix.com/tests/htmdlg.htm");
var openBtn = browser.FindElement("input button", "text=Open Modal Box");

// Click the button that opens the modal dialog.

openBtn.Click();

var modalFrame = browser.FindModalHtmlDialog();

WScript.Sleep(2000);

// Click the button that closes the modal dialog.
var closeBtn = modalFrame.FindElement("input button");
closeBtn.Click();


IE6 - IE9 macro - automate modal HTML dialog boxes opened by showModelessDialog

FindModelessHtmlDialog - web automation method

Connects a Frame IE automation object to a modeless dialog box that displays a HTML document (see showModelessDialog).

Applies to:
Browser
  var modelessFrame = browser.FindModelessHtmlDialog(Search conditions);
Arguments:
This method accepts a variable number of Search Condition arguments. If no search condition is provided, then the first modeless frame is returned. Any HTML frame or iframe attribute is accepted in search conditions.
Remarks:
The method returns a Frame IE macro object corresponding to a HTML modeless dialog box created by showModelessDialog method. If no modeless HTML dialog box is found, then null is returned. Internet Explorer pop-up blocker may block HTML dialogs. In case of an error the method throws a script exception and the lastError property of the core object is set as follows:
  • BROWSER_CONNECTION_LOST_ERROR: if the browser was closed.
  • FAIL_ERROR: in case of anohter error.

The time allocated for search is specified by the searchTimeout property. If loadTimeout is not zero, then the method waits the browser objects to be completely loaded in the amount of time specified by the property. If the timeout has expired the lastError property is set to LOAD_TIMEOUT_ERROR. In this case, if loadTimeoutIsError property is true, then a IE macro exception is thrown.
Example:
var coreObj = new ActiveXObject("Twebst.Core");
var browser = coreObj.StartBrowser("http://www.codecentrix.com/tests/htmdlg.htm");
var openBtn = browser.FindElement("input button", "text=Open Modeless Box");

// Click the button that opens the modeless dialog.

openBtn.Click();

var modelessFrame = browser.FindModelessHtmlDialog();

WScript.Sleep(2000);

// Click the button that closes the modeless dialog.
var closeBtn = modelessFrame.FindElement("input button");
closeBtn.Click();


IE6-IE9 macro recorder - get programmatic control over parent IHTMLElement in C#

FindParentElement - web automation method

Searches a parent IHTMLElement up in the HTML DOM hierarchy that matches a tag-name and verifies a list of Search Conditions.

Applies to:
Element
  var parent = element.FindParentElement("tag_name", Search conditions);
Arguments:
This method accepts a variable number of Search Condition arguments. Any HTML attribute is accepted in search conditions. Text is also accepted as attribute in search conditions, in this case the text of the HTML element is used in search. If no search condition is provided, the first parent element that matches the tag_name is returned. If the tag_name is empty, the first parent that matches the search condition arguments is returned.
  • tag_name is the HTML tag of the element to be found (can be empty string).
Remarks:
The method returns an web macro Element object that matches the search condition arguments and has the specified tag_name. It provides programmatic control over the underlying IHTMLElement native object exposed by IE browser. If no element verifies the search conditions, then null is returned.
In case of an error the method throws a IE macro exception and the lastError property of the core object is set as follows:
  • INVALID_ARG_ERROR: if invalid parameters are provided
  • BROWSER_CONNECTION_LOST_ERROR: if the browser was closed.
  • FAIL_ERROR: in case of anohter error.

The time allocated for search is specified by the searchTimeout property. The search is affected by useRegExp property. If loadTimeout is not zero, then the method waits the browser objects to be completely loaded in the amount of time specified by the property. If the timeout has expired the lastError property is set to LOAD_TIMEOUT_ERROR. In this case, if loadTimeoutIsError property is true, then a IE automation exception is thrown.
Example:
var core    = new ActiveXObject("Twebst.Core");
var browser = core.StartBrowser("http://www.google.com/");
var elem    = browser.FindElement("input text");

// Search the first parent having the name "f".
var parent = elem.FindParentElement("", "name=f");
WScript.Echo(parent.tagName + " " + parent.nativeElement.innerText);


IE9 macro recorder - automate HTML dropdown and list boxe controls in C#

GetAllSelectedOptions - web automation method

Retrieves the collection of selected options in a HTML list-box ( IHTMLSelectElement ) control.

Applies to:
Element
  var optionsList = elementObj.GetAllSelectedOptions();
Arguments:
None.
Remarks:
If no option is selected inside dropdown/list-box then an empty IE automation ElementList object is returned after searchTimeout has expired. It can be applied only to <select> objects, otherwise a script exception is thrown and the lastError property is set to INVALID_OPERATION_ERROR.

The time allocated for finding the selected options list is specified by the searchTimeout property. If loadTimeout is not zero, then the method waits the browser objects to be completely loaded in the amount of time specified by the property. If the timeout has expired the lastError property is set to LOAD_TIMEOUT_ERROR. In this case, if loadTimeoutIsError property is true, then a IE macro exception is thrown.
Example:
// Displays all selected options in a select object.
var coreObj = new ActiveXObject("Twebst.Core");
var browser = coreObj.StartBrowser("http://www.codecentrix.com/tests/qt3.htm");
var select  = browser.FindElement("select");
var optList = select.GetAllSelectedOptions();
var text    = "";

for (var i = 0; i < optList.length; ++i)
{
    text += optList.item(i).text;
    text += "\n";
}

WScript.Echo(text);


Web scraping - extract HTML attributes from IE web pages.

GetAttribute - web automation method

Extract the value of the specified attribute of an IHTMLElement inside a web page.

Applies to:
Element
  var attr = elementObj.GetAttribute(attrName);
Arguments:
  • attrName is the name of the attribute to be retrieved.
Remarks:
If the attribute is not present, this method returns empty string. The attribute name is case insensitive. When retrieving the CLASS attribute using this method, set the attrName to be "className", which is the corresponding Dynamic HTML (DHTML) property.
Example:

None.


Automate copy-paste clipboard operations between web pages with IE macros

GetClipboardText - web automation method

The method extracts text data from the clipboard.

Applies to:
Core
  var text = coreObj.GetClipboardText();
Arguments:
None.
Remarks:
The method extracts text data from the clipboard in Unicode/ANSI format. The method throws a IE macro exception if the clipboard operation fails. In this case the lastError property of the Core object is set to FAIL_ERROR.
Example:
var coreObj       = new ActiveXObject("Twebst.Core");
var clipboardText = coreObj.GetClipboardText();

WScript.Echo(clipboardText);


IE9 macro recorder - find and highlight IHTMLElement in VBA

Highlight - web automation method

Highlights IHTMLElement objects.

Applies to:
Element
  elementObj.Highlight();
Arguments:
None.
Remarks:
The method will cause the border of the IHTMLElement to flash so that it can be easily located on the screen. This method can be useful for debugging IE macros when you want to verify that the correct HTML element was found.
Example:
var coreObj = new ActiveXObject("Twebst.Core");
var browser = coreObj.StartBrowser("http://www.codecentrix.com");

var element = browser.FindElement("a", "text=Download");
element.Highlight();


IE6-IE9 automation - programmatically fill out web forms in C#, VB.Net, C++ by simulating users keystrokes

InputText - web automation method

IE automation method that simulates users keystrokes inside web forms editable controls ( IHTMLInputElement and IHTMLTextAreaElement ).

Applies to:
Element
  elementObj.InputText("input_string");
Arguments:
  • input_string is the string that contains the keystrokes to be automatically generated.
Remarks:
This IE automation method automatically fills out web forms by simulating keystrokes in HTML editable controls, using hardware or Internet Explorer HTML events, depending on useHardwareInputEvents property. All necessary HTML events are fired up to simulate user's behavior (onkeydown, onkeydown, onkeyup, onkeypress, onchange). If the method is applied to an Element that is not an editable control, then an IE automation exception is thrown and the lastError property is set to INVALID_OPERATION_ERROR.
Example:
// Assume nativeEdit is a <input type="text"> HTML element.
var coreObj = new ActiveXObject("Twebst.Core");
var e       = coreObj.AttachToNativeElement(nativeEdit);
e.InputText("abcdefgh");


Internet Explorer Automation and MSHTML programming - automate IWebBrowser2 and IHTMLWindow2 in C#, VB.Net and C++

NativeWindowToNativeBrowser - web automation method

Not available in Open Twebst edition!
Internet Explorer automation method that returns a native Internet Explorer browser object ( IWebBrowser2 ) from a native window object ( IHTMLWindow2 ).

Applies to:
Core
  var nativeBrowser = coreObj.NativeWindowToNativeBrowser(nativeWindow);
Arguments:
  • nativeWindow is the native IHTMLWindow2 window object to be converted to a native IWebBrowser2 browser.
Remarks:
This Internet Explorer automation method may return null (for example in case of HTML modal/modeless dialog boxes). Converting a IHTMLWindow2 to a IWebBrowser2 may prove useful for BHO/IE extensions and MSHTML programming.
Example:

None.


Internet Explorer Automation and MSHTML programming - automate IHTMLDocument2 and IHTMLWindow2 in C#, VB.Net and C++

NativeWindowToNativeDocument - web automation method

Not available in Open Twebst edition!
Internet Explorer automation method that returns a native Internet Explorer document object ( IHTMLDocument2 ) from a native window object ( IHTMLWindow2 ).

Applies to:
Core
  var nativeDocument = coreObj.NativeWindowToNativeDocument(nativeWindow);
Arguments:
  • nativeWindow is the native IHTMLWindow2 window object to be converted to a native IHTMLDocument2 document.
Remarks:
The method is useful for BHO/IE extensions and MSHTML programming, when the document is not directly accessible due to cross-domain frame scripting security restriction. Read more about this on When IHTMLWindow2::get_document returns E_ACCESSDENIED and When IHTMLWindow2.document throws UnauthorizedAccessException articles.
Example:

None.


Internet Explore Automation - programatically open URL in VBA, C#

Navigate - web automation method

Internet Explorer automation method that navigates the browser to a given URL.

Applies to:
Browser
  browserObj.Navigate(url_string);
Arguments:
  • url_string is the URL where the browser will navigate.
Remarks:
This Internet Explorer automation method works for all versions: IE6, IE7, IE8 and with IE protected mode on Windows XP, Vista and Win7. In case of failure this method throws a Internet Explorer automation exception and the lastError property of the Core object is set to FAIL_ERROR or BROWSER_CONNECTION_LOST_ERROR.
Example:
var coreObj    = new ActiveXObject("Twebst.Core");
var newBrowser = coreObj.StartBrowser("http://www.codecentrix.blogspot.com/");
newBrowser.Navigate("http://www.codecentrix.com/");


Programmatically open a new tab window in IE7, IE8 and IE9 with Excel/VBA web macro

OpenNewTab - web automation method

Not available in Open Twebst edition!
Opens a new Internet Explorer tab window and returns a Browser web macro object connected to it. This Internet Explorer automation method works for all browser versions: IE6, IE7, IE8 and with UAC and IE protected mode on Windows XP, Vista and Win7.

Applies to:
Browser
  var tabBrowser = browserObj.OpenNewTab("url");
Arguments:
  • url is the URL where the newly opened tab will navigate.
Remarks:
This IE automation method is available only for Internet Explorer 7 or higher.
The URL of the newly opened tab is specified by the url parameter. The tab opens inside the same main frame IE window as the calling Browser tab. The method throws a web macro exception if a new tab cannot be open. In this case the lastError property of the Core object is set to FAIL_ERROR.
Example:
var coreObj    = new ActiveXObject("Twebst.Core");
var newBrowser = coreObj.StartBrowser("http://www.codecentrix.com/");
var newTab     = newBrowser.OpenNewTab("http://google.com/");


IE8 automation in C# - remove attributes from MSHTML IHTMLDOMNode

RemoveAttribute - web automation method

IE automation method that removes an HTML attribute from an Element object.

Applies to:
Element
  elementObj.RemoveAttribute(attrName);
Arguments:
  • attrName is the name of the attribute to be removed.
Remarks:
The HTML attribute name is case insensitive. When removing the CLASS attribute using this method, specify the sName to be "className", which is the corresponding Dynamic HTML (DHTML) property.
Example:

None.


Web automation - Twebst Automation Studio IE automation software

Reset - web automation method

Resets web automation core object.

Applies to:
Core
  coreObj.Reset();
Arguments:
None.
Remarks:
Resets all properties of web automation core oject to their default values.
Example:
var coreObj = new ActiveXObject("Twebst.Core");
coreObj.Reset();


Web Automation Software - simulate right click on web controls (anchors, buttons, checkboxes, radios, submit)

RightClick - web automation method

Web automation method that simulates a mouse right click on a HTML web control.

Applies to:
Element
  elementObj.RightClick();
Arguments:
None.
Remarks:
This web automation method simulates a right click on any HTML element using hardware or Internet Explorer events, depending on useHardwareInputEvents property. All necessary HTML events are fired up to simulate user's behavior (onmouseover, onmousemove, onmousedown, onbeforeactivate, onactivate, onfocusin, onfocus, onmouseup).
Example:

None.


Web data extraction - web scraping images from a web site with VBScript, JScript, C#, VB.Net

SaveElementImage - web automation method

Not available in Open Twebst edition!
Scrap the image an HTML element from a web site and save it to a graphic file (BMP, GIF, JPG, PNG).

Applies to:
Element
  elementObj.SaveElementImage("file_name");
Arguments:
  • file_name is the name of the graphic file where the image will be saved.
Remarks:
This web scraping method extracts the image (as it appears on the screen) of an HTML element and saves it to a specified graphic file. The supported image file formats are: BMP, GIF, JPG, PNG. An extension for the image file name must be provided. In case of an error, a web macro exception is thrown and the lastError property is set to FAIL_ERROR.
Example:
// Save all the existing images in a web page.
var coreObj = new ActiveXObject("Twebst.Core");
var browser = coreObj.StartBrowser("http://www.codecentrix.com");

var images = browser.FindAllElements("img");
for (i = 0; i < images.length; ++i)
{
    images(i).SaveElementImage("c:\\img" + i + ".jpg");
}


Web browser automation - programatically select options in HTML drop-down and list-box web controls with VBScript or JScript

Select - web automation method

Browser automation method that selects options in HTML combo-box (drop-down) or list-box web controls.

Applies to:
Element
  elementObj.Select(item_to_select);
Arguments:
  • item_to_select is the text or the ordinal position of the option to be selected.
Remarks:
Any previous selection in the HTML drop-down / listbox control is removed.
The input parameter can be:
  • a number that represents the zero-based ordinal position of the option to be selected.
  • a string that represents the text of the option to be selected. If useRegExp property is true:
    • For multiple selection list-box all the options that match the input regular expression are selected.
    • For combo-box (drop-down) and single selection list-box, the first option that matches the input regular expression is selected.
If no option matches the input parameter, then a browser automation exception is thrown and the lastError property is set to NOT_FOUND_ERROR
If the browser automation method is applied to an Element that is not a combo-box (drop-down) or list-box control, then a browser automation exception is thrown and the lastError property is set to INVALID_OPERATION_ERROR.

The time allocated for selecting the options is specified by the searchTimeout property. If loadTimeout is not zero, then the method waits the browser objects to be completely loaded in the amount of time specified by the property. If the timeout has expired the lastError property is set to LOAD_TIMEOUT_ERROR. In this case, if loadTimeoutIsError property is true, then a script exception is thrown.
Example:
// Assume nativeCombo is a <select> HTML element.
// Select the first item in the combo-box.
var coreObj = new ActiveXObject("Twebst.Core");
var combo   = coreObj.AttachToNativeElement(nativeCombo);
combo.Select(0);


IE9 automation with C# and .Net - full control over HTML drop-down and list-box web controls

SelectRange - web automation method

IE automation method that selects a range of options in HTML multiple selection list-box web controls.

Applies to:
Element
  elementObj.SelectRange(start_range, end_range);
Arguments:
  • start_range is the text or the ordinal position of the first option in the range to be selected.
  • end_range is the text or the ordinal position of the last option in the range to be selected.
Remarks:
Any previous selection in the HTML web control is removed and the options between start_range and end_range are selected.
Each of the two input parameters can be:
  • a number that represents the zero-based ordinal position of the option to be the limit of the range.
  • a string that represents the text of the option to be the limit of the range.. If useRegExp property is true, then the limit of the range must match the regular expression represented by the input string parameter.
If the speciffied range is empty (no option matches the input parameters), then a script exception is thrown and the lastError property is set to NOT_FOUND_ERROR
If the IE automation method is applied to an Element that is not a multiple selection list-box web control, then a script exception is thrown and the lastError property is set to INVALID_OPERATION_ERROR.

The time allocated for selecting the options is specified by the searchTimeout property. If loadTimeout is not zero, then the method waits the browser objects to be completely loaded in the amount of time specified by the property. If the timeout has expired the lastError property is set to LOAD_TIMEOUT_ERROR. In this case, if loadTimeoutIsError property is true, then a script exception is thrown.
Example:
// Assume nativeList is a <select multiple> HTML element.
// Select the first two items in the multiple selection list-box control.
var coreObj = new ActiveXObject("Twebst.Core");
var list    = coreObj.AttachToNativeElement(nativeList);
list.SelectRange(0, 1);


Browser automation - programmatically access HTML attributes of a IHTMLDOMNode in C#

SetAttribute - web automation method

Browser automation method that sets the value of the specified HTML attribute.

Applies to:
Element
  elementObj.SetAttribute(attrName, attrValue);
Arguments:
  • attrName is the name of the attribute to be set.
  • attrValue is the string, number, or boolean to assign to the attribute.
Remarks:
When setting the CLASS attribute using this method, set the sName to be "className", which is the corresponding Dynamic HTML (DHTML) property.
Example:

None.


IE macro - automate web site copy-paste clipboard operations in VBScript and JScript

SetClipboardText - web automation method

This IE automation method places text on the clipboard.

Applies to:
Core
  coreObj.SetClipboardText(text);
Arguments:
  • text is the text to be placed on the clipboard.
Remarks:
The text is placed on the clipboard in both ANSI and Unicode format. The method throws a web macro exception if the clipboard operation fails. In this case the lastError property of the Core object is set to FAIL_ERROR.
Example:
var coreObj = new ActiveXObject("Twebst.Core");
coreObj.SetClipboardText("Twebst Web Automation Library");

var clipboardText = coreObj.GetClipboardText();
WScript.Echo(clipboardText);


Internet Explorer Automation - show, hide, maximize, minimize, restore and put in foreground IEFrame top window

ShowBrowserWindow - web automation method

Not available in Open Twebst edition!
Shows, hides, maximizes, minimizes, restores or puts in foreground the browser window.

Applies to:
Browser
  browserObj.ShowBrowserWindow(show_window_constant);
Arguments:
  • show_window_constant is one of the following browser constants: SHOW_IN_FOREGROUND, SHOW_HIDE, SHOW_MAXIMIZE, SHOW_MINIMIZE, SHOW_RESTORE, SHOW_VISIBLE.
Remarks:
In case of failure this method throws a script exception and the lastError property of the Core object is set to FAIL_ERROR or BROWSER_CONNECTION_LOST_ERROR.
Example:
var coreObj    = new ActiveXObject("Twebst.Core");
var newBrowser = coreObj.StartBrowser("http://www.codecentrix.com/");
newBrowser.ShowBrowserWindow(newBrowser.SHOW_IN_FOREGROUND);


Internet Explorer Macro - programmatically open URLs in IE6 - IE9 with protected mode

StartBrowser - web automation method

Starts a new instance of Internet Explorer browser with an appropriate integrity level and returns a Browser web macro object connected to it. This Internet Explorer automation method works for all browser versions: IE6, IE7, IE8 and IE9 and with IE protected mode on Windows XP, Vista and Win7.

Applies to:
Core
  var b = coreObj.StartBrowser("url");
Arguments:
  • url is the URL where the newly started browser will navigate first.
Remarks:
The URL of the newly started browser is specified by the url parameter. The method throws a web macro exception if a new browser instance can not be started. In this case the lastError property of the Core object is set to FAIL_ERROR.
Example:
var coreObj    = new ActiveXObject("Twebst.Core");
var newBrowser = coreObj.StartBrowser("http://www.codecentrix.com/");


Internet Explorer Automation in C# and VB.Net - programmatically launch URLs in IE6 - IE9 with an appropriate integrity level

StartHiddenBrowser - web automation method

Not available in Open Twebst edition!
Starts a new invisible instance of Internet ExplorerInternet Explorer browser and returns a Browser web automation object connected to it.

Applies to:
Core
  var b = coreObj.StartHiddenBrowser("url");
Arguments:
  • url is the URL where the newly started hidden browser will navigate first.
Remarks:
The window of the newly started browser is invisible and the URL is specified by the url parameter. The method throws a web macro exception if a new browser instance can not be started. In this case the lastError property of the Core object is set to FAIL_ERROR. This Internet Explorer automation method works for all browser versions: IE6, IE7, IE8 and IE9 and with IE protected mode on Windows XP, Vista and Win7.
Example:
var coreObj    = new ActiveXObject("Twebst.Core");
var newBrowser = coreObj.StartHiddenBrowser("http://www.codecentrix.com/");
newBrowser.ShowBrowserWindow(newBrowser.SHOW_VISIBLE);


IE9 automation from Excel/VBA - automate checkbox web controls and fire up onclick HTML event

Uncheck - web automation method

Sets the checked state of a checkbox web control to false. All necessary HTML events are fired up to simulate user's behavior.

Applies to:
Element
  checkboxObj.Uncheck();
Arguments:
None.
Remarks:
The method clears a selected checkbox by simulating a click on the HTML element using hardware or Internet Explorer events, depending on useHardwareInputEvents property. If the element is already un-checked, the method returns immediately. The method can only be applied to <input type=checkbox> elements, otherwise a web macro exception is thrown and the lastError property is set to INVALID_OPERATION_ERROR. To clear a selected radio button, select another button in the set.
Example:

None.


Internet Explorer Automation with VBA/Excel - wait untill frame/iframe DOM hierarchy is loaded

WaitToLoad - web automation method

Waits the browser to load and check it against a list of Search Conditions.

Applies to:
Browser
  var boolResult = browserObj.WaitToLoad(Search conditions);
Arguments:
The method accepts a variable number of Search Condition arguments. The following attributes are accepted in search conditions:
  • TITLE condition on the title of the browser window
  • URL condition on the url of the web page
Remarks:
This IE automation method returns true if the browser is completely loaded in the amount of time specified by loadTimeout property and it verifies the list of Search Conditions input parameters. If loadTimeout property is zero, then only the check against Search Conditions parameters is performed.
If load timeout has expired and the browser is not completely loaded then lastError property is set to LOAD_TIMEOUT_ERROR. In this case, if loadTimeoutIsError is true, then a web automation exception is thrown. In case of an error the method throws a web automation exception and the lastError property of the core object is set as follows:
  • INVALID_ARG_ERROR: if invalid parameters are provided.
  • FAIL_ERROR: in case of anohter error.
Example:
var coreObj = new ActiveXObject("Twebst.Core");
var browser = coreObj.StartBrowser("http://www.codecentrix.com/");
browser.WaitToLoad();


C#/C++ MSHTML programming - automate IHTMLDocument2 and Internet Explorer_Server window in C#, VB.Net and C++

WndToNativeDocument - web automation method

Not available in Open Twebst edition!
Retrieves a native HTML document object ( IHTMLDocument2 ) from a Internet Explorer_Server Win32 window handle.

Applies to:
Core
  var nativeDoc = core.WndToNativeDocument(ieWndHandle);
Arguments:
  • ieWndHandle is a Win32 API window handle.
Remarks:
ieWndHandle parameter is the handle of a Internet Explorer_Server window hosted by any application. This IE automation method can be useful if you already have a handle of a browser control hosted inside a .Net WinForms application and you need to access the HTML document. In case of an error the method throws a web automation exception and the lastError property of the core object is set as follows:
  • INVALID_ARG_ERROR: if ieWndHandle parameter is not a valid Internet Explorer_Server window handle.
  • FAIL_ERROR: in case of anohter error.
Example:
// Assume ieWnd it is a valid handle to a 'Internet Explorer_Server' window.
var ieWnd     = 0xA10AF0;
var coreObj   = new ActiveXObject("Twebst.Core");
var nativeDoc = coreObj.WndToNativeDocument(ieWnd);

WScrip.Echo("The document size is: " + nativeDoc.fileSize);