"SWITCH_WINDOW" Command
Description: This command switches to another window identified by a unique popup text, handle index (0,1,2) or main window. Please note that Locator-based commands will switch window to the Locator-defined window. Use this command to switch window for commands like EXECUTE_JAVASCRIPT or with popups that are automatically displayed. Switch Duration parameter is used to override the default behavior of locator-based elements. Without using this parameter, the locator-based commands will switch window to the windows defined by the locator. If the whole test case option is used for this new parameter, the locator-based commands will not switch to the window defined by the locator but instead will continue using the window from this command throughout the rest of the test case or until another Switch_Window command is issued with the Default option.
To guarantee switching to a specific window, after you navigate to that window, create a step with Switch_Window command, select Handler Index and use the number to assign the window with this number (number must not be more than the number of open windows).
Usage Scenario: Suppose we want to open Reference app on 3 windows and switch from the 3rd window to the second and then to the main window.
Procedure: 1. Define a Goto_URL step as your starting point and two steps with Execute_Javascript for the navigation of the second and third windows using the code:
window.open("https://reference.subject-7.com");
2. After each navigation step, add a step with Switch_Window command, select Handle Index option and enter the number to assign the windows. For example, the first tab will be 0, the second tab will be 1 and the third tab will be 2.
3. At the end, add 3 steps with Switch_Window command which will perform the actual switching between tabs to make sure that the numbers assigned are correct. Your steps will look like this:
You can try this by pasting the SLL snippet below into your test case by going to More > Advanced View
WEB GOTO_URL "https://reference.subject-7.com" HALT ON ERROR
WEB SWITCH WINDOW BY HANDLER "0" DURATION_TYPE WHOLE_TEST_CASE HALT ON ERROR
WAIT 3 HALT ON ERROR
WEB EXECUTE SCRIPT "window.open('http://subject7.com')" LOCATORS HALT ON ERROR
WEB SWITCH WINDOW BY HANDLER "1" DURATION_TYPE WHOLE_TEST_CASE HALT ON ERROR
WAIT 3 HALT ON ERROR
WEB EXECUTE SCRIPT "window.open('http://myreference.subject-7.com/')" LOCATORS HALT ON ERROR
WEB SWITCH WINDOW BY HANDLER "2" DURATION_TYPE WHOLE_TEST_CASE HALT ON ERROR
WAIT 3 HALT ON ERROR
WEB SWITCH WINDOW BY HANDLER "1" DURATION_TYPE WHOLE_TEST_CASE HALT ON ERROR
WAIT 3 HALT ON ERROR
WEB SWITCH WINDOW BY HANDLER "0" DURATION_TYPE WHOLE_TEST_CASE HALT ON ERROR