BrowserFind Function

Action

Finds a DOM element using a given locator.

Include file

BrowserAPI.bdh

Syntax

BrowserFind( nHandle        : in number,
             sLocator       : in string,
             bStoreHandle   : in boolean optional,
             nTimeout       : in union optional,
             bSuppressError : in boolean optional ): number;
Parameter Description
nHandle The handle where the search should be started. Use HANDLE_DESKTOP to search the complete DOM hierarchy.
sLocator An XPath expression that describes the DOM element.
bStoreHandle Optional: The browser engine can internally store the found handle for later use. You can use HANDLE_STORED to refer to the internally stored element in other function calls. If not specified, the default value FALSE is used and the handle will not be stored.
nTimeout Optional: The wait timeout in milliseconds. If not specified, the default timeout specified in the profile settings or set by BrowserSetOption(BROWSER_OPT_WAIT_TIMEOUT) will be used. When the timeout is reached, an error is thrown, unless bSuppressError is TRUE. Use the data type number for this parameter. The data type float is not allowed.
bSuppressError Optional: If set to TRUE, suppresses throwing the error if no element can be found. Default is FALSE.

Return value

The handle to the DOM element. HANDLE_INVALID if the element could not be found.

Example

benchmark SilkPerformerRecorder

use "Kernel.bdh"
use "BrowserAPI.bdh"

dcluser
  user
    VUser
  transactions
    TInit           : begin;
    TMain           : 1;

var

dclrand

dcltrans
  transaction TInit
  begin
  end TInit;

  transaction TMain
  var
    liHandle : number;
    liText : string;
  begin
    BrowserStart(BROWSER_MODE_DEFAULT, 800, 600);
    BrowserNavigate("http://demo.borland.com");
    
    // find the first list item (LI) tag on this page and store it into a variable (liHandle)
    liHandle := BrowserFind(HANDLE_DESKTOP, "//LI");    
    // Alternative: find the first list item (LI) tag on this page and store it internally (HANDLE_STORED)
    BrowserFind(HANDLE_DESKTOP, "//LI", true);    
    // get the text of the list item and print it
    BrowserGetText(liHandle, liText);
    print(liText);    
    //Alternative: get the text of the list item and print it
    BrowserGetText(HANDLE_STORED, liText);
    print(liText);
  end TMain;