Skip to content
Sahi Pro Flowcharts is retired. These pages document the last release (v12) and are no longer updated. Go to the current documentation.Flowcharts is retired. Current docs
Get Free Trial
Sahi Pro Flowcharts is retired. These pages document the last release (v12) and are no longer updated. Go to the current documentation.

Secondary Windows (Popup Windows)

Applications may open secondary windows as a new window or in a new tab. This section shows how to automate secondary windows.

We handle secondary windows using 2 APIs.

Modes BrowserWindowsJavaSAP

This action allows selecting a window before performing further actions.

Parameters

NameTypeDescription
$windowIdentifierstringoptionalthe windowIdentifier can be the window name, the window title, or the window URL, or a regular expression of any of these. To reference the base window, omit this parameter or use null. The windowIdentifier can also be the sahiWinId.
Raw script
// switch to popWin popup window
_selectWindow("popWin");
// perform actions on popWin
_assertEqual("Link Test", _getText(_link(0))); // no mention of popWin needed
var $href;
_set($href, _link(0).href); // no mention of popWin needed
...
// switch back to base window
_selectWindow();
// perform actions on base window

Sahi Pro Classic API _selectWindow

Modes BrowserWindowsJava

Returns an array of window-property objects. A window-property is just an associative array with the following attributes:

Attribute Description
windowName window name
windowTitle window title
windowURL URL of top window
wasOpened ‘0’ or ‘1’ as string. 0 means base window, 1 means popup window
domain document.domain of window, if set
isIFrame ‘0’ or ‘1’ as string. 1 means iframe window
initialTime Timestamp when window was opened
lastTime Timestamp of last ping from that window
sahiWinId sahiWinId for that window

Parameters

NameTypeDescription
$activePeriodintegeroptionaltime in milliseconds to return windows within the time. Default is 0, which returns all windows. This argument is valid only in Browser Mode.
$includeIframesbooleanoptionalflag to get all windows including iframes. Default is false, which returns non-iframe windows. This argument is valid only in Browser Mode. This argument is available since Sahi Pro v9.1.0.

Returns

li_mpArray of window-property objects
Raw script
// Example:
_navigateTo("http://sahi.co.in/demo/");
_click(_link("Window Open Test With Title"));
_wait(2000);
var $windows = _getWindows();
_assertEqual(2, $windows.length);
_assertEqual('With Title', $windows[1].windowTitle);
_assertEqual("1", $windows[1].wasOpened);

Sahi Pro Classic API _getWindows

Modes BrowserWindowsJava

Returns true if the window exists.

Parameters

NameTypeDescription
$windowIdentifierstringThe windowIdentifier can be the window name, the window title, the window URL or the sahiWinId, or a regular expression of any of these.
$activePeriodintegeroptionalTime interval in milliseconds within which the specified window is checked for activity. Default is -1, which means the specified window is checked amongst all windows opened during the session. Available only for browser.

Returns

booleantrue if the window exists, else false
Raw script
// Example:
_navigateTo("/demo/");
_click(_link("Window Open Test"));
_wait(3000);
var $exists = _windowExists("/demo/");
var $exists2 = _windowExists("popWin");
_assertTrue($exists);
_assertTrue($exists2);
var $recentWindowId = _getRecentWindow().sahiWinId;
var $exists3 = _windowExists($recentWindowId);
_assertTrue($exists3);
_selectWindow("popWin");
_closeWindow(); // Closes the popup window
_selectWindow();
_wait(3000); // Wait for 3 seconds
var $exists3 = _windowExists("popWin", 3000); // Now _windowExists returns false.
_assertFalse($exists3);

Sahi Pro Classic API _windowExists

Modes Browser

Returns the most recent (last opened) window. Refer to _getWindows for all properties of window object returned.

Parameters

NameTypeDescription
None

Returns

mpMost recent (last opened) window
Raw script
// Example:
_navigateTo("/demo/");
_click(_link("Window Open Test"));
_click(_link("Window Open Test With Title"));
_wait(2000);
var $recentWindow = _getRecentWindow();
_assertEqual('With Title', $recentWindow.windowTitle); // This is the window opened by clicking the link "Window Open Test With Title".
_assertEqual("1", $recentWindow.wasOpened);

Sahi Pro Classic API _getRecentWindow