Protractor E2E Testing Error : Object [object Object] has no method 'getWindowHandle'

随声附和 提交于 2019-12-05 08:34:11

Here is what I currently use to navigate through popups/tabs :

// do stuff that will trigger the popup
// ...
browser.getAllWindowHandles().then(function (handles) {
  // switch to the popup
  browser.switchTo().window(handles[1]);
  // make sure the popup is now focused
  expect(browser.getCurrentUrl()).toEqual('popup/url');
  // do stuff with the popup
  // ...
  // go back to the main window
  browser.switchTo().window(handles[0]);
  // make sure we are back to the main window
  expect(browser.getCurrentUrl()).toEqual('original/url');
});

You just need to make sure that your popup is really a new window and not juste some kind of popover ( in which case you can just target it with css selectors ).

Another thing to keep in mind when you change tabs/popups it that the target page might not have angularjs loaded in it, which will render protractor useles. If you face this case you can simply use browser.driver as a replacement for browser to navigate a non angular page.

Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!