Sahi Pro - How does Sahi identify elements?

Sahi can identify elements in various ways.

Standard attributes

Sahi has access to the DOM of the html page. Thus it can identify elements using their attributes. Depending upon the type of the element, Sahi uses the visible text, name, id, class, associatedLabel, index etc to identify the element. More details can be found in the Accessor APIs section.

Custom attributes

It is also possible to add a custom property to an element and have Sahi identify the element through the custom property.

Let us say you had a custom identifier called customid in your checkbox element.

You can make the following changes to have the Sahi controller identify the checkbox element by its customid.
  1. Take a backup of htdocs/spr/concat.js.
  2. Edit concat.js. Search for the line containing
    this.addAD({tag: "INPUT", type: "checkbox"
  3. Replace the following line
    this.addAD({tag: "INPUT", type: "checkbox", event:"click", name: "_checkbox", attributes: ["name", "id", "value",
    "className", "index"], action: "_click", value: "checked",
    assertions: function(value){return [("true" == ("" + value)) ?
    _sahi.language.ASSERT_CHECKED : _sahi.language.ASSERT_NOT_CHECKED];}});
    with
    this.addAD({tag: "INPUT", type: "checkbox", event:"click", name: "_checkbox", attributes: ["name", "id", "value",
    "className", "index", "customid"], action: "_click", value: "checked",
    assertions: function(value){return [("true" == ("" + value)) ?
    _sahi.language.ASSERT_CHECKED : _sahi.language.ASSERT_NOT_CHECKED];}});
    infoNOTE the addition of "customid".
  4. Restart Sahi server and clear browser cache.
  5. Now a checkbox can be identified through the "customid" attribute as well.

Relation to an anchor element

An element can be identified in relation to other anchor elements on the page. This includes _in, _near, _under etc. For more details, please refer to Relation APIs page.