Sahi Documentation

Multiple Domains in a Page

Web pages can contain frames and iframes loading from different domains. For example a news page from one domain may show facebook likes coming from the facebook domain. When frames or iframes in a page are loaded from a domain different from the parent page, Sahi needs to select the domain in the script to see the elements in the frame.

Sahi can target a particular domain using 2 APIs.

_selectDomain

Since: Sahi ProSahi OSSahi Pro StarterDesktop Add-OnMobile Add-OnSAP Add-OnAI Assist Add-On
3.537.0.1NANANANA

Available for modes: Browser

_selectDomain([$domainIdentifier])

Arguments
$domainIdentifierstring optional Can be the domain name or a regular expression of it. To reference the base domain, omit this parameter or use null.

Returns
null

Details

info This is the recommended way of working with domains.
This API allows selecting a domain before performing further actions.
// switch to frame of domain www.domain1.com
_selectDomain("www.domain1.com");
// perform actions on frame
_assertEqual("Link Test", _getText(_link(0))); // no mention of domain needed
var $href;
_set($href, _link(0).href); // no mention of domain needed
// or
var $href = _fetch(_link(0).href); // no mention of domain needed
...
// switch back to domain of top frame
_selectDomain();
// perform actions on domain of top frame


// To reference a domain along with its protocol, pass the protocol also. Eg.
_selectDomain("https://www.domain1.com");


_domain

Since: Sahi ProSahi OSSahi Pro StarterDesktop Add-OnMobile Add-OnSAP Add-OnAI Assist Add-On
3.537.0.1NANANANA

Available for modes: Browser

_domain([$domainIdentifier])

Arguments
$domainIdentifierstring optional Can be the domain name or a regular expression of it. To reference the base domain, omit this parameter or use null.

Returns
null

Details

Any step to be executed on a particular domain would be prefixed by _domain("domainIdentifier").

warning _domain is ONLY used as a PREFIX to Sahi Action APIs
// clicks link in frame of domain "www.domain1.com"
_domain("www.domain1.com")._click(_link(0));
// domain by regular expression
_domain("/.*domain1.*/")._click(_link(0));


warning This API may be confusing while fetching attribute values or using assertions.
To fetch a value or asserting. this needs to be used a particular way.
_domain("www.domain1.com")._assertEqual("Link Test", _getText(_link(0))); // CORRECT
_assertEqual("Link Test", _domain("www.domain1.com")._getText(_link(0))); // WRONG

var $href;
_domain("www.domain1.com")._set($href, _link(0).href); // CORRECT
_set($href, _domain("www.domain1.com")._link(0).href); // WRONG
It is better to use the _selectDomain API instead.