Relational Accessor Functions
_in
Parameters: accessorDescription:Example:
link("delete", in(_cell("del2")))
_near | near
Parameters: elementDescription: the element should be searched nearfor in relation to another element, instead of by its own attributes. They make a locator more robust when the target element has no stable id, name, or text of its own — typically inside tables, menus, and repeated card layouts.
Summary
_ininside another element_nearnearest to another element (by distance)An icon or button next to a known label
_aboveabove another elementA column header for a cell below it
_belowbelow another elementA value under a known header
_rightOfto the right of another elementThe cell beside a row label
_leftOfto the left of another elementThe row label beside a known cell
_in
Searches for the element within another element. Scope a generic locator to the region of the page where it is expected, which removes ambiguity when the same text or tag appears several times.
_navigateTo("https://www.apple.com/the ");_click(_link("ac-gn-Products" linkac-gn-link-mac"));_click(_link("ac-gn-that lives inside the /products linkac-gn-link-iphone"click(span("Products",_near(_link(_in(link("/ipad/"products"))));_near
Searches for the element near another element. The accessor works from the centre point of the nearby elements and calculates the distance between the centre of the reference point and the surrounding objects in every direction.
The number written before
sets the order in which the system picks near objects:_click(_link(near0is the nearest,1the second nearest, and so on.// nearest element to the "Label Page" link link(0, near("Label Page")); /ipad// second nearest element to the same reference point link(1, near("Label Page"));
and_click(_span(_near_belowresolve positions with x/y coordinates, so they are the two accessors most sensitive to a changed page layout._above and _below
Searches for the element above or below another element. Both are most useful when working with tables, where the row label and the value share no attributes.
_above strong("chapternav-label[1]Type", _above(strong("Size"))) _below strong("Size",_near(_link(_below(strong("Type")))_rightOf and _leftOf
Searches for the element to the right or to the left of another element. Same syntax as the other relational accessors.
_rightOf cell("Tote", _rightOf(strong("Type"))) _leftOf strong("Type", _leftOf(cell("Tote")))Example — all six accessors on one page
navigateTo("https://demosite.appvance.com/"); click(span("Ruby on Rails Tote")); setDescription("Using in Relational Accessor"); click(span("Products", _in(link("/ipad/products")))); click(span("Ruby on Rails Tote")); setDescription("Using rightOf Relational Accessor"); assertExists(cell("Tote", _rightOf(strong("Type")))); setDescription("Using leftOf Relational Accessor"); assertExists(strong("Type", _leftOf(cell("Tote")))); setDescription("Using above Relational Accessor"); assertExists(strong("Type", _above(strong("Size")))); setDescription("Using below Relational Accessor"); assertExists(strong("Size", _below(strong("Type"))));