Skip to content Skip to sidebar Skip to footer

Switching To New Window With Selenium/protractor Javascript

Looking for some help on how I should be getting ahold of a new 'pop-up' window that is triggered to display after I click a 'login' button. I am able to get to when the window is

Solution 1:

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.

Solution 2:

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 importantvar winHandles=browser.getAllWindowHandles();
winHandles.then(function(handles) 
{
    var parentWindow=handles[0];
    var popUpWindow=handles[1];
    browser.switchTo().window(popUpWindow);
    browser.switchTo().window(parentWindow);
})

Solution 3:

If you are calling https:// url and again redirect to http:// url then this popup is coming because of security issue.

1 - You have to configure both application in https:// or http://

Post a Comment for "Switching To New Window With Selenium/protractor Javascript"