Switching to new window with Selenium/Protractor Javascript

前端 未结 3 808
北恋
北恋 2020-12-09 20:22

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

相关标签:
3条回答
  • 2020-12-09 20:56

    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.

    0 讨论(0)
  • 2020-12-09 21:01

    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);
    })
    
    0 讨论(0)
  • 2020-12-09 21:02

    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://

    0 讨论(0)
提交回复
热议问题