Seeking assistance with accessing a new "pop-up" window that appears after clicking a "login" button.
The code I am currently using to capture the window handle seems to be ineffective even though I am able to reach the displayed window. My scenario involves using protractor within my pages, but the new non-angular based window requires me to switch to using Selenium WebDriver while in that window. (Is there a potential issue with this approach?)
Below is the snippet of code used to create the selenium driver and an attempt to switch to the new pop-up window's handle. I keep encountering "No Such Element" errors when trying to locate a form on the page.
// Create selenium webdriver / driver
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
// Ensure the new window pops up and we navigate to it correctly
var handlePromise = browser.driver.getAllWindowHandles();
handlePromise.then(function (handles) {
var popUpHandle = handles[1];
// Change to the new handle
browser.driver.switchTo().window(popUpHandle);
var popUpHandleFinal = browser.driver.getWindowHandle();
expect(popUpHandleFinal).toEqual(popUpHandle);
});
A few points to address:
If I remove "browser" from "browser.driver.switchTo().window(popUpHandle)" and use just "driver.switchTo().window(popUpHandle)", I encounter an error stating "UnknownError: unknown error: 'name' must be a nonempty string." This is because the "switchTo()" method on driver cannot be null. The error resolves when using the original code.
I'm unsure if I should be utilizing protractor (global "browser" variable) or defaulting to "driver" (Selenium) for managing windows.
Appreciate any guidance you can provide.