Switching to new window with Selenium/Protractor Javascript

前端 未结 3 828
北恋
北恋 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.

提交回复
热议问题