In the fourth post on the Five Questions Series, we have Sahi Relational APIs today.Previous posts in this series: Sahi Controller, Sahi Logs and Sahi Excel Framework.

What is Sahi Relational API Some times, elements are not uniquely identifiable by themselves. Identifying them in relation to either some element near them or by the element in which they are contained helps. Sahi Relational APIs help you solve that problem. The Relational APIs can be used even on applications with dynamic ids to easily locate one element with respect to another.

Please list the different APIs (markers) under DOM and Positional Relational APIs There are 2 kinds of relation APIs: DOM Relation APIs and Positional Relation APIs. DOM relation markers like _near, _in specify that the element should be searched near or within another element. Position relations like under, rightOf, leftOf, etc. relate one element to another via their position. The list is as follows:

DOM Relation APIs:_near, _in, _startLookInside, _stopLookInsidePositional Relation APIs:_rightOf, _leftOf, _leftOrRightOf, _under, _above, _aboveOrUnderParent APIs:_parentNode, _parentCell, _parentRow, _parentTable

How to identify elements using relational APIs?Identify the main element or the element which is easily identifiable. Then, anchor it and identify the (hard to identify) element in relation to the main element.Let us take an example to highlight this. In the sample application, we have three books Core Java, Ruby for Rails and Python Cookbook. We also have a text field against each of them.

Relational APIs: Sample Application
Relational APIs: Sample Application

Suppose, we want to identify the text field against the Ruby for Rails. Notice the accessor of the element when no relational API is used. It reads _textbox(โ€œq[1]โ€).

Relational APIs: Element Accessor without Relational API
Relational APIs: Element Accessor without Relational API[/caption]
Relational APIs: Identify Ruby for Rails