Fetching multiple elements? _collect APIs to your rescue.

  • 1
  • April 10, 2017

There are multiple cases in automation where you would like to fetch multiple elements. In such cases, you can use any of the three APIs – _collect, _collectAttributes and _collectElementsInfo.
Let us see each API in detail.

_collect:
This API returns an array of element stubs of all elements of type apiType matching the identifier within relations.

Syntax:
_collect($apiType, $identifier[, $relations ...])

$apiType string type of elements to collect. Eg. "_link", "_button", "/text/" etc.
$identifier string|int Sahi Identifier. Can also be just an index.
$relations … relations optional Relations like _in, _near etc.

The next API to check out is _collectAttributes
This returns an array of element attributes of all elements of type apiType matching the identifier within relations.

Syntax:
_collectAttributes($apiType, $identifier, $attribute[, $relations ...])

$apiType string type of elements to collect. Eg. "_link", "_button", "/text/" etc.
$identifier string|int Sahi Identifier. Can also be just an index.
$attribute attribute|function attribute or function.
$relations … relations optional Relations like _in, _near etc.This can fetch

This API can fetch

  • a simple attribute from multiple elements
  • one of the few simple attributes from multiple elements
  • some synthesized/processed values from multiple elements by executing
    • an inline function for each element
    • a defined function for each element
    • nested functions

The third API to note is _collectElementsInfo
This API returns array of Accessor Info object of all elements of type apiType within relations.

Syntax:
_collectElementsInfo($apiType[, $relations ...])

$apiType string Type of elements to collect. Can be regular expression. Eg. "_link", "_button", "/text/" etc.
$relations … relations optional Relations like _in, _near etc.

To know more about Fetch APIs, please refer this link: http://sahipro.com/docs/sahi-apis/fetch-apis.html

Feel free to write your questions to support [at] sahipro [dot] com

Leave a Reply

Your email address will not be published.

Use fully-loaded Sahi Pro FREE for a month. Download Now Request a Demo