Using Locators

Within Silk4J, literal references to identified objects are referred to as locators. For convenience, you can use shortened forms for the locator strings in scripts. Silk4J automatically expands the syntax to use full locator strings when you playback a script. When you manually code a script, you can omit the following parts in the following order:

  • The search scope, //.
  • The object type name. Silk4J defaults to the class name.
  • The surrounding square brackets of the attributes, [ ].

When you manually code a script, we recommend that you use the shortest form available.

Note: When you identify an object, the full locator string is captured by default.
The following locators are equivalent:
  • The first example uses the full locator string.
    _desktop.<DomLink>find("//BrowserApplication//BrowserWindow//a[@textContents='Home']").select();

    To confirm the full locator string, use the Locator Spy dialog box.

  • The second example works when the browser window already exists.
    browserWindow.<DomLink>find("//a[@textContents='Home']").select();

To find an object that has no real attributes for identification, use the index. For instance, to select the second hyperlink on a Web page, you can type:

browserWindow.<DomLink>find("//DomLink[2]").select();

Additionally, to find the first object of its kind, which might be useful if the object has no real attributes, you can type:

browserWindow.<DomLink>find("//DomLink").select();