Frames and IFrames

Frames from same domain

Sahi automatically traverses across frames and iframes when it tries to identify any element. If there are 2 textboxes with name "user" on the page, one in the main page and the other in an iframe, Sahi will automatically identify the textboxes as _textbox("user") and _textbox("user[1]").

In most cases the tester does not need to know or bother about frames and iframes.

Frames from different domains

When a child frame is from a domain different from the top frame domain, Sahi needs to know which frame or iframe it has to communicate to.

When a child frame or iframe is from a different domain, say x.example.com, Sahi will prefix the statements with _domain("x.example.com").

While locating elements in a page, all iframes/frames from a particular domain will be treated as a continuous unit and indexes will span across these frames.

Frame1 Domain: www.domain1.com
_textbox("user") without any domain prefix
Frame2 Domain: www.domain2.com
_textbox("user")
used with prefix
_domain("www.domain2.com").
Frame3 Domain: www.domain2.com
_textbox("user[1]")
used with prefix
_domain("www.domain2.com").
Frame4 Domain: www.domain3.com
_textbox("user") used with _domain("www.domain3.com"). prefix
Frame1 Domain: www.domain1.com
_textbox("user[1]") without any domain prefix
To work with frames from different domains, either use the _domain prefix or use _selectDomain API as mentioned Multiple Domains section.

Subdomains with document.domain

When frames are from the same domain but from different sub domains, the webpage may enable javascript interaction between the frames by setting the document.domain attribute to a common parent domain via javascript.

For example, if Frame1 is from x.domain1.com and Frame2 is from y.domain1.com, they cannot access each other via javascript. To enable interaction, the page authors can set document.domain='domain1.com' in their javascript code.

When Sahi navigates to such pages, the Controller may not work on some frames. To check whether frames have set the document.domain, do one of the following:
  1. open the Controller Evaluate Expression box, type document.domain and click "Test-->". You may see something like this: .domain1.com or domain1.com

    Check the domain in the URL: If it is bigger like x.domain1.com then you know that document.domain has been set.
  2. Do a "view source" on the page and search for document.domain. You may see something like:
    document.domain = "domain1.com"
To make Sahi work with such pages:
  1. Open sahi/userdata/config/domainfix.txt
  2. Add
    *.maindomain.com maindomain.com
  3. Save, restart Sahi, clear browser cache and check. The Controller should now work correctly.