I'm trying to write e2e login test to my application which uses oauth2. when clicking the facbook login- another window opened (the facebook login). I'm trying to enter the credentials there. I'm currently using
browser.driver.switchTo().window();
because it is a new window. I've read that I can get the name of the window by entering 'window.name' in the console. when doing that I got '_e_02MT' I have also tried 'window.document.title' and got 'Facebook' I've tried the different combinations of
browser.driver.switchTo().window('_e_02MT');
browser.switchTo().window('Facebook');
browser.driver.switchTo().window('Facebook');
and so on still can't get to that window. I'm getting the error:
NoSuchWindowError: no such window
any ideas?
thanks.
Instead of a name of the window, you need to provide a handle:
browser.getAllWindowHandles().then(function (handles) {
// switch to the popup
browser.switchTo().window(handles[1]);
// do stuff with the popup
// ...
// go back to the main window
browser.switchTo().window(handles[0]);
});