Switching to new window with Selenium/Protractor Javascript

As of latest version of Protractor (v2.2) there should not be an issue in using protractor window handles, which returns an array of windows that are currently being displayed. As P.T has pointed out there is no need to invoke a separate driver instance but a browser global variable will work. The window that invokes popup has array index of 0 and popup window will have an array index of 1. Below is a sample of switching to the pop up window to work on it.

browser.getAllWindowHandles().then(function(handles){
    browser.switchTo().window(handles[1]).then(function(){
        //do your stuff on the pop up window
    });
});

Hope this helps.


If you are clicking any link or button in order to open a pop up window, add some wait after click using browser.sleep(ms).

This worked for me and got rid of an error "missing 'handle' parameter"

element(by.className("name")).click();
browser.sleep(10000); //This line is important
var winHandles=browser.getAllWindowHandles();
winHandles.then(function(handles) 
{
    var parentWindow=handles[0];
    var popUpWindow=handles[1];
    browser.switchTo().window(popUpWindow);
    browser.switchTo().window(parentWindow);
})